int fscanf(FILE *stream, const char *format, ...);我可以使用fscanf()从文件中读取整数。我如何读取在换行符后面的整数
发布于 2011-09-10 04:13:33
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;
}发布于 2011-09-10 05:02:02
scan直到换行符,然后读一个int。例如:
fscanf(filePointer, "%s\n%d", firstline, &theInteger); 如果行上有更多的内容,则可能需要修改格式。
https://stackoverflow.com/questions/7369549
复制相似问题