gpt4 book ai didi

c - 如何读取c中换行后出现的整数?

转载 作者:行者123 更新时间:2023-11-30 14:27:44 24 4
gpt4 key购买 nike

int fscanf(FILE *stream, const char *format, ...);

我可以使用fscanf()从文件中读取整数。如何读取换行符后面的整数?

最佳答案

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;
}

关于c - 如何读取c中换行后出现的整数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7369549/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com