I am using fscanf() function to read data line by line from a text file. It was functioning fine but suddenly I don't know what mistake I made and now the function returns a negative value. below is my code snippet:
FILE *fp;
char ip[16];
int port;
fp = fopen("ClientInformation.txt", "r");
int size = -1;
while (!feof(fp))
{
fgetc(fp);
size++;
}
char buff[1000];
sprintf(buff,"%i",size);
MessageBox(NULL,
buff,
"Size",
MB_ICONINFORMATION);
if(size > 0)
{
while (fscanf(fp, " %s %d", ip, &port) > 0)
{
MessageBox(NULL,"fscanf() Successful","SUCCESS!", MB_ICONINFORMATION);
}
}