按线路读取线和匹配模式-C
我有一个文本文件,其中包含如下行:
“字符串可能包含多个单词 - 字符串与前一个字符串相同 - 数量”
我用 fgets 逐行读取该文件,但 sscanf 只是切断了除第一个字符串之外的所有内容。 我该如何解决这个问题?
char new_name[30], new_district[30], buffer[100];
unsigned new_part_count;
while(fgets(buffer, 100, file)) {
sscanf(buffer, "%s - %s - %u", new_name, new_district, &new_part_count);
}
I have a text file with lines like this:
"string maybe contains more than one word - string as the previous -
number"
I read from this file line by line with fgets, but the sscanf just cut off everything except the first string.
How can I solve this problem?
char new_name[30], new_district[30], buffer[100];
unsigned new_part_count;
while(fgets(buffer, 100, file)) {
sscanf(buffer, "%s - %s - %u", new_name, new_district, &new_part_count);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试以下调用,
如果仅使用转换说明器
%s
,则任何白空间字符终止字符串的输入。Try the following call
If to use just the conversion specifier
%s
then any white space character terminates the input of a string.