我正在寻找一个相当简单问题的解决方案:
- 有一个文本文件,其中单词\字符串以“\n”分隔,每个新字符串在“\n”之后开始
- 需要从文件中获取这些字符串中的每一个,并从中创建一个单独的实体。
最佳答案
是的,这个任务听起来非常简单,除了从字符串中“创建一个单独的实体”的模糊想法(???)。
如果我要实现这样的程序,我将使用以下通用算法:
#include <stdio.h>
#define LEN 0xFF
int main(int argc, char ** argv) {
char line[LEN];
FILE * input_file = NULL;
if ((input_file=fopen("myinputfile.txt","r")) == NULL) {
// Handle error when opening the file...
}
while (fgets(line, LEN, input_file) != NULL) {
// Process each line of input...
}
fclose(input_file);
return 0;
}
关于c - 如何从 C 文本文件中的字符串创建单独的实体?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13881756/