int fscanf(FILE *stream, const char *format, ...);
我可以使用fscanf()
从文件中读取整数。如何在换行符后立即读取的整数?
答案 0 :(得分:2)
fscanf()
- 看一下这个例子。
这就是你想要的东西:
#include <stdio.h>
int main()
{
int n;
FILE * pFile;
pFile = fopen("myfile.txt", "r");
// Repeat this as many times as necessary
fscanf(pFile, "\n%d", &n);
printf("%d\n", n);
fclose(pFile);
return 0;
}
答案 1 :(得分:0)
scan
直到换行,然后阅读int
。例如:
fscanf(filePointer, "%s\n%d", firstline, &theInteger);
如果线路上有更多东西,可能需要修改格式。