Hey guys,
I tried searching, but could not fix the problem I'm having. I basically want to read in from a file that has data delimited by a ; . But its not printing any of the array values into the 2nd file.
I checked the return code on the fscanf (read in of values) and its only returning 1, which is not right. What am I doing wrong ?
Text File:
Code:
1000;Cash;Common Shares Issued;c;4000.000000;
3000;Common Shares Outstanding;Common Shares;c;0.000000;
Program:
Code:
int ViewJournal(){
FILE *fp;
FILE *fp2;
int Counter2=0, Counter=0, b=0;
int Account[MAX_ITEMS]={0};
char Description[MAX_ITEMS][31]={0};
char TransType[MAX_ITEMS]={0};
double Amount[MAX_ITEMS]={0};
char AcctDescription[MAX_ITEMS][31]={0};
fp = fopen("tr.dat", "r");
if (fp != NULL){
while (fscanf(fp,"%d[^;];%30[^;];%30[^;];%2[^;];%lf[^;\n]%*c", &Account[Counter], AcctDescription[Counter], Description[Counter], TransType[Counter], &Amount[Counter] == 5);
counter++;
}
fclose(fp);
}
else {
printf("\n ERROR: FILE NOT FOUND!");
}
fp2 = fopen("gj.txt", "w");
fprintf(fp2,"\n\t\t\tGeneral Journal");
fprintf(fp2,"\n\t\tAccount\tDescription \tDebit\tCredit");
fprintf(fp2,"\n\t\t-------\t-------------\t-----\t------");
for (Counter2=0;Counter2<Counter;Counter2++){
if (TransType[Counter2] == 'c' || TransType[Counter2] == 'C'){
fprintf(fp2,"\n\t\t%d\t%s\t\t\t%.2lf", Account[Counter2], Description[Counter2], Amount[Counter2]);
}
else if (TransType[Counter2] == 'd' || TransType[Counter2] == 'D'){
fprintf(fp2,"\n\t\t%d\t%s\t\t%.2lf", Account[Counter2], Description[Counter2], Amount[Counter2]);
}
}
fclose(fp2);
return 0;