0

我正在从文件中读取此文本:

file1: file2,file3,file4
file10: testfile.h
file1: file9

并将其拆分

while(fscanf(fp,"%[^:]: %s",map[i].name, map[i].filesNeeded) == 2)
{
    printf("%s %s",map[i].name, map[i].filesNeeded);
    i++;
}

问题是第二个和第三个变量是用前导换行符保存的:

Details:{name = "\\nfile10", '\\000' <repeats 56 times>, filesNeeded = "testfile.h", '\\000' <repeat

如何在没有前导换行符的情况下保存它?

4

1 回答 1

2

" %[^:]: %s "

while(fscanf(fp," %[^:]: %s ",map[i].name, map[i].filesNeeded) == 2)

scanf中的空格吸收空格字符、制表符、换行符

于 2012-11-13T08:46:26.930 回答