从文本文件读入数组到C编程语言
问题描述:
如何读入数组中一个带有空格的字符串,用C编程语言中的文本文件中的分号分隔?从文本文件读入数组到C编程语言
***from textfile***
"My Record; My Second Record; My Third"
。 。 。
fopen ...
for(i = 0; i < 3; i++) {
fscanf_s(myFile, "%s", myRecords[i].title); /* this want read the records */
}
fclose...
答
最明显的可能性是使用scanset
转换:
fscanf_s(myFile, "%[^;]", myRecords[i].title);
格式应为 “%[^];”跳过前导空格并阅读分号。因此,文本文件中的第三条记录应该有一个分号结束符。 – 2009-11-30 19:56:19
@Steve:好点。 – 2009-11-30 20:00:01
好了,我跟着你的评论史蒂夫。 – 2009-11-30 20:44:58