#define F_PWD_FSCANF "%05d%30[^\n]%15s%25s%30s\n"
#define F_PWD_FPRINTF "%05d%-30s%-15s%-25s%-30s\n"
int main(){
FILE *fp=fopen(FILENAME(F_PWD),"a+");
if (!fp)
{
perror("ERROR:");
FreeMalloc(pw,pw_t);
exit(EXIT_FAILURE);
}
while(!feof(fp))
{
count++;
fscanf(fp,F_PWD_FSCANF,&pw_t->id,pw_t->name,pw_t->userID,pw_t->pwd,pw_t->emailID);
if ((strcmp(pw->userID, pw_t->userID)==0) || (strcmp(pw->emailID, pw_t->emailID)==0))
{
printf("\n[%s]-[%s] ",pw->userID,pw_t->userID);
printf("\n[%s]-[%s] ",pw->emailID,pw_t->emailID);
COLOR(RED);
ToastMsg(TOAST_MSG_USER_EMAIL_EXISTS, row_x, col_y,1500);
COLOR(YEL);
ToastMsg( TOAST_MSG_OPTION, row_x, col_y,0);
retVal=1;
while_loop=false;
break;
}
printf("\neof loop");
}
return 0;
}
File created with fprintf()
00001Anil Dhar anil1960 -N[VY&# anil.dhar@live.com
00002Rita Dhar anil1960 -_VaN&# rita.dhar@gmail.com
00003Shailja Dhar shailja1960 -`UNVYWN&# shailja.dhar@me.com
00004Tony P Singh tony1234 -a[f ! tony@x.com
However, I am unable to read this file using fscanf() because it doesn't satisfy the eof condition. As a result, it goes into an endless loop.
The fprintf() and fscanf() format specifiers are defined as pre-processor dietcrivers.
What is wrong with the code?