我正在从文件中读取此文本:
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
如何在没有前导换行符的情况下保存它?
答案 0 :(得分:2)
为" %[^:]: %s "
while(fscanf(fp," %[^:]: %s ",map[i].name, map[i].filesNeeded) == 2)
scanf中的空格吸收空格字符,制表字符,新行字符