Well while reading my file backwards and making sure I am not at the top , in the debugger I realized ftell stop returning a position can anyone shed some light ?
int Dtl(Acc *user)
{
FILE *dtl_Fp;
trans_Pass dislog[10];
int i=0,x=-1,r_Val;
My_Convertor();
dtl_Fp=Opnfile("Tempfile",r_B,dnt_ret_fp);
system("cls");
printf("Types Format\nW-Withdraw\tDep-Deposit\tSch-Pay School Fee\n\nID:NO\tTyp:Amount\t\tDate\n");
while (1)
{
fseek(dtl_Fp,sizeof(trans_Pass)*(x),SEEK_END);
fread(&dislog[i],sizeof(trans_Pass),1,dtl_Fp);
r_Val=ftell(dtl_Fp);
if ((ftell(dtl_Fp)==0)){break;}
if(dislog[i].id_No==user->id_No){printf("%s\n\n",dislog[i].info);}
i++;x--;
}
fclose(dtl_Fp);
}
It might have something to do with:
r_Val=ftell(dtl_Fp);
if ((ftell(dtl_Fp)==0)){break;}
You are calling ftell() twice, but never using r_val.
There is nothing in the code segment that allows me to see the value of sizeof(trans_Pass)*(x)
, the argument in fseek(), but if it is not a legal value (0, file size) it could result in unexpected result.
There is no guarantee that ftell()
is not returning a -1. You are not checking for that. Upon an error condition, ftell returns -1, then sets errno to a nonzero value which can be used to get information on the nature of the error.