我正在使用 fscanf() 函数从文本文件中逐行读取数据。它运行良好,但突然间我不知道我犯了什么错误,现在该函数返回一个负值。下面是我的代码片段:
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);
}
}