fscanf在读取文件中的数据时返回什么?例如:
int number1, number2, number3, number4, c;
c = fscanf (spFile, "%d", &number1);
//c will be 1 in this case.
c = fscanf (spFile, "%d %d %d %d", &number1, &number1, &number3, &number4);
//in this case, c will return 4.
我只想知道为什么它会根据参数数量返回这样的值。
fscanf
失败,它将返回EOF
。在C中,EOF
是一个实现定义的值,您可以使用宏EOF
进行测试。因此,您可以说if c == EOF { /* do something */ }
来检查返回值c
。 - Charles Salviawhile (fscanf(stdin, "%s", buf)!=EOF){ printf("value read: [%s]\n", buf); }
- EsmaeelE