我有一个从文件xxx.conf
读取数据配置的程序FILE *file = fopen("xxx.cof", "rb");
然后数据以
给出char line[128];
while(fgets(line, sizeof(line), file))
我想将文件xxx.conf替换为字符串文件=" name = xxxx \ nsurname = xxx \ n adress = xxx"
我希望程序从字符串中读取数据。
相反
FILE *file = fopen("xxx.conf", "rb"):
file = "name = xxx\nsurnam =xxx\nadress = xxx"
答案 0 :(得分:1)
如果我理解你的问题,你应该使用strtok
char line[] = "name = xxx\nsurnam =xxx\nadress = xxx";
char *entry;
entry = strtok(line, "\n");
while (entry)
{
printf("%s\n", entry);
entry = strtok(NULL, "\n");
}
只需用代码替换printf