【发布时间】:2013-01-01 15:08:24
【问题描述】:
我有一个字符串如下
char row[]="11/12/1999 foo:bar some data..... ms:12123343 hot:32";
我想使用 sscanf 将 'ms' val 插入到 int 变量中。 但我不知道如何配置 ssscanf 以忽略行中的第一个数据。 我尝试打击,但没有完成这项工作。
int i;
sscanf(row,".*ms:%d",i);
【问题讨论】:
-
sscanf(strstr(row, "ms:") + 3, "%d", &i); -
如果你知道只有一个冒号,你也可以
sscanf(row, "%*[^:]:%d", &i);。 -
不,还有其他冒号
-
@herzlshemuelian 试试我的答案,我还给了一个链接打开第二个答案
-
@GrijeshChauhan 谢谢我写了关于你的解决方案的评论。