Click here to Skip to main content
15,891,033 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Not catching the exception Pin
Emilio Garavaglia28-May-10 2:04
Emilio Garavaglia28-May-10 2:04 
GeneralRe: Not catching the exception Pin
sashoalm28-May-10 2:21
sashoalm28-May-10 2:21 
GeneralRe: Not catching the exception Pin
Stephen Hewitt28-May-10 5:08
Stephen Hewitt28-May-10 5:08 
QuestionResizing image Pin
learningvisualc27-May-10 20:48
learningvisualc27-May-10 20:48 
AnswerRe: Resizing image Pin
Code-o-mat27-May-10 21:21
Code-o-mat27-May-10 21:21 
AnswerRe: Resizing image Pin
CPallini27-May-10 21:31
mveCPallini27-May-10 21:31 
AnswerRe: Resizing image Pin
Anu Koshy1-Jun-10 23:35
Anu Koshy1-Jun-10 23:35 
QuestionCompiling C programs in VS.NET 2005 Pin
Sadheesh R27-May-10 20:13
Sadheesh R27-May-10 20:13 
I have a C program, which has to be compiled in VS.NET 2005 environment. I don't have any issues with the compilation part and the EXE is generated. When I run the EXE the program is looping. Pls find below the source code:

/* ------------------------------------------------------------------------ */
/* Program Name : GLDBACK2.C */
/* Last Modified : 03/11/08 - RMC - Creation date */
/* N.B. GLD0DETL has 190 fields and is 1287 bytes */
/* */
/* ------------------------------------------------------------------------ */

/************************************************************************** */
/* Reads dBase file and outputs as text file. */
/* Based on Valour Software freeware. */
/************************************************************************** */

#include <fcntl.h>
#include <sys\types.h>
#include <sys\stat.h>
#include <io.h>
#include <malloc.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef struct dbase_head {
unsigned char version; /*03 for dbIII and 83 for dbIII w/memo file*/
unsigned char l_update[3]; /*yymmdd for last update*/
unsigned long count; /*number of records in file*/
unsigned int header; /*length of the header
*includes the \r at end
*/
unsigned int lrecl; /*length of a record
*includes the delete
*byte
*/
unsigned char reserv[20];
} DBASE_HEAD;

typedef struct dbase_fld {
char name[11]; /*field name*/
char type; /*field type*/
#define DB_FLD_CHAR 'C'
#define DB_FLD_NUM 'N'
#define DB_FLD_LOGIC 'L'
#define DB_FLD_MEMO 'M'
#define DB_FLD_DATE 'D'
/* A-T uses large data model but drop it for now */
//char far *data_ptr; /*pointer into buffer*/
unsigned char length; /*field length*/
unsigned char dec_point; /*field decimal point*/
unsigned char fill[14];
} DBASE_FIELD;

typedef struct fld_list {
struct fld_list *next;
DBASE_FIELD *fld;
char *data;
} FLD_LIST;

DBASE_HEAD dbhead={0};
FLD_LIST *db_fld_root=0;
char *Buffer;
char buf_work[255];
int dbfile;

int ck, fldtotal;
unsigned long reccount;
int fldcount=0;
FILE *outtxt, *infotxt;
char OUTNAME[50]= "";
char INFONAME[50]= "";
char *outf, *infof;
char *envSys;
char *envBrNo;


/*------------------------------------------------------------code-------*/
main(argc,argv)
int argc;
char *argv[];
{
printf("\nGLDBACK2\n");
if(argc!=2)
emessage("Usage is db_dump","filename.dbf", -1);


envSys = getenv("SYS");
envBrNo = getenv("BRN");


outf = OUTNAME;
infof = INFONAME;

sprintf(outf, "H:\\%s\\DATA\\BRANCH%s\\DATALOC\\glddbf.txt",envSys,envBrNo);
sprintf(infof, "H:\\%s\\DATA\\BRANCH%s\\DATALOC\\gldinfo.txt",envSys,envBrNo);


outtxt = fopen(OUTNAME,"w");
if (outtxt == 0)
{
emessage("Opening","glddbf", outtxt);
exit(2);
}

infotxt = fopen(INFONAME,"w");
if (infotxt == 0)
{
emessage("Opening","gldinfo", infotxt);
exit(2);
}

dbfile=open(argv[1],O_RDONLY);
if(dbfile==-1)
{emessage("Unable to open file",argv[1], -1);}

/* read data dictionary */
printf("Reading data dictionary\n");
db3_read_dic();

/* write out records */
printf("Writing records...\n");
db3_print_recs();

printf("\n\nProcessing complete\n");
close(dbfile);
exit(0);

/* Close output text file */
ck=fclose(outtxt);
if (ck != 0)
{
emessage("Closing","glddbf",ck);
exit(2);
}

}

/******************************************************
db3_read_dic()
This function is called with a file name to
read to create a record type to support the
dbase file
******************************************************/

db3_read_dic()
{
int fields;
DBASE_FIELD *fld;

if(dbfile==-1) {
printf("open failed");
exit(200);
}
read(dbfile,&dbhead,sizeof(DBASE_HEAD));
if( !(dbhead.version==3 || dbhead.version==0x83) )
{
printf("\n\aVersion %d not supported",dbhead.version);
emessage("Version not","supported", -1);
}

fprintf(infotxt, "update year %3d",dbhead.l_update[0]);
fprintf(infotxt, "update mon %3d",dbhead.l_update[1]);
fprintf(infotxt, "update day %3d",dbhead.l_update[2]);
fprintf(infotxt, "number of recs %6u",dbhead.count);
reccount = dbhead.count;
fprintf(infotxt, "header length %3d",dbhead.header);
fprintf(infotxt, "record length %3d\n",dbhead.lrecl);
Buffer=malloc(dbhead.lrecl);

printf("\nHeader reccount = %6u\n", reccount);

fldtotal = 0;
fields=(dbhead.header-1)/32-1;
fprintf(infotxt, "Field Name\tType\tLength\tDecimal Pos\n");
while(fields--) {
fld=(DBASE_FIELD *)malloc(sizeof(DBASE_FIELD));
if(!fld)
emessage("Not enough memory","DBASE_FIELD", -1);
read(dbfile,fld,sizeof(DBASE_FIELD));
fprintf(infotxt, "%-10s\t %c\t %3d\t %3d\n",fld->name,fld->type,
fld->length,fld->dec_point);
++fldtotal;
stack_field(fld);
}
read(dbfile,Buffer,1); /*read the silly little \r character*/

printf("Number of fields = %6d\n", fldtotal);

/* Close info text file */
ck=fclose(infotxt);
if (ck != 0)
{
emessage("Closing","gldinfo",ck);
exit(2);
}

return;
}

/******************************************************
db3_print_recs()
Read records and print the data
******************************************************/

db3_print_recs()

{
int bytes;
unsigned long readcnt=0;
int maxflag=0; /* max count = 65536 */
double maxcnt=0;

while(Buffer[0]!='*')
{
bytes=read(dbfile,Buffer,dbhead.lrecl);
if(bytes!=dbhead.lrecl)
break;
if(Buffer[0]!='*') {
db3_print();
++readcnt;
if(readcnt==65536)
{
printf("\ncount boundary reached\n");
maxflag=1;
}
printf("Writing record number %6u\r", readcnt);
}
}
if(maxflag==1)
{
maxcnt = readcnt;
printf("\nFinal number written is %0.6f\n", maxcnt);
}
return;
}


/******************************************************
db3_print()
Print a single record
******************************************************/

db3_print()
{
FLD_LIST *list, *temp;

temp=db_fld_root;

while(temp) {
memcpy(buf_work,temp->data,temp->fld->length);
++fldcount;
buf_work[temp->fld->length]='\0';
if (fldcount==fldtotal)
{fldcount=0;
fprintf(outtxt,"%s\n",buf_work);}
else
{fprintf(outtxt,"%s",buf_work);}
temp=temp->next;
}
return;
}

/******************************************************
stack_field()
Add a field to the linked list of fields
******************************************************/

stack_field(fld)
DBASE_FIELD *fld;
{
FLD_LIST *list, *temp;

list=(FLD_LIST *)calloc(1,sizeof(FLD_LIST));
if(!list)
emessage("Not enough memory","FLD_LIST", -1);
list->fld=fld;
if(!db_fld_root) {
list->data=Buffer+1; /*skip delete byte*/
db_fld_root=list;
return;
}
temp=db_fld_root;
while(temp->next)
temp=temp->next;
temp->next=list;
list->data=temp->data + temp->fld->length;
return;
}



/***********************/
/* emessage routine */
/***********************/
emessage(edesc,efile,ecode)
char edesc[7];
char efile[8];
int ecode;
{
printf ("\n\n***************************************************************\n");
printf ("** **\n");
printf ("** Error %s %s file. Status = %2d **\n",edesc,efile,ecode);
printf ("** **\n");
printf ("** Print This Screen and **\n");
printf ("** **\n");
printf ("** PLEASE CALL LONDON SUPPORT **\n");
printf ("** **\n");
printf ("***************************************************************\n");
printf("\nPress any key to continue ");
getchar();

return (9);
}

/* End of program */


The function db3_read_dic() is reading a .DBF file and writing the header details to a .TXT file. In that process, the record length is 0. The same EXE generated from MC6 environment works fine. But when the program is being compiled in VS.NET, it loops. Any idea?
AnswerRe: Compiling C programs in VS.NET 2005 Pin
Cedric Moonen27-May-10 20:21
Cedric Moonen27-May-10 20:21 
AnswerRe: Compiling C programs in VS.NET 2005 Pin
Aescleal27-May-10 20:56
Aescleal27-May-10 20:56 
GeneralRe: Compiling C programs in VS.NET 2005 Pin
Sadheesh R27-May-10 22:47
Sadheesh R27-May-10 22:47 
GeneralRe: Compiling C programs in VS.NET 2005 Pin
Aescleal27-May-10 23:20
Aescleal27-May-10 23:20 
GeneralRe: Compiling C programs in VS.NET 2005 Pin
Sadheesh R27-May-10 23:37
Sadheesh R27-May-10 23:37 
GeneralRe: Compiling C programs in VS.NET 2005 Pin
Aescleal27-May-10 23:43
Aescleal27-May-10 23:43 
QuestionEdit Selection Color Pin
john563227-May-10 19:38
john563227-May-10 19:38 
AnswerRe: Edit Selection Color Pin
john563228-May-10 2:09
john563228-May-10 2:09 
QuestionHow to save unicode text in the source code of vc++ 6.0 IDE Pin
Jayapal Chandran27-May-10 19:07
Jayapal Chandran27-May-10 19:07 
AnswerRe: How to save unicode text in the source code of vc++ 6.0 IDE Pin
Stephen Hewitt27-May-10 19:37
Stephen Hewitt27-May-10 19:37 
GeneralRe: How to save unicode text in the source code of vc++ 6.0 IDE Pin
Jayapal Chandran28-May-10 8:42
Jayapal Chandran28-May-10 8:42 
GeneralRe: How to save unicode text in the source code of vc++ 6.0 IDE Pin
Jayapal Chandran28-May-10 8:44
Jayapal Chandran28-May-10 8:44 
AnswerRe: How to save unicode text in the source code of vc++ 6.0 IDE Pin
sashoalm27-May-10 23:28
sashoalm27-May-10 23:28 
GeneralRe: How to save unicode text in the source code of vc++ 6.0 IDE Pin
Jayapal Chandran28-May-10 8:48
Jayapal Chandran28-May-10 8:48 
GeneralRe: How to save unicode text in the source code of vc++ 6.0 IDE Pin
Jayapal Chandran28-May-10 9:02
Jayapal Chandran28-May-10 9:02 
Questionvector of doubles (division) Pin
b-rad31127-May-10 9:57
b-rad31127-May-10 9:57 
AnswerRe: vector of doubles (division) Pin
loyal ginger27-May-10 10:10
loyal ginger27-May-10 10:10 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.