在 C 中读取 txt 文件并将解析的字符串保存到数组中可以使用 fopen() 和 fscanf() 函数。代码示例如下:
```c #include <stdio.h>
int main() { char str[100]; FILE *fp = fopen("example.txt", "r"); int i = 0; while(fscanf(fp, "%s", str) != EOF) { printf("%s\n", str); i++; } fclose(fp); return 0; } `
该代码示例展示了如何在C程序中使用fopen和fscanf函数打开名为example.txt的文本文件,逐行读取内容并将其作为字符串保存到一个字符数组中。
9125

被折叠的 条评论
为什么被折叠?



