【发布时间】:2011-10-25 09:05:08
【问题描述】:
我正在尝试使用sscanf从字符串中提取一个字符串和一个整数:
#include<stdio.h>
int main()
{
char Command[20] = "command:3";
char Keyword[20];
int Context;
sscanf(Command, "%s:%d", Keyword, &Context);
printf("Keyword:%s\n",Keyword);
printf("Context:%d",Context);
getch();
return 0;
}
但这给了我输出:
Keyword:command:3
Context:1971293397
我期待这个输出:
Keyword:command
Context:3
为什么sscanf 会这样?提前感谢您的帮助!
【问题讨论】:
-
您是否有充分的理由不检查
sscanf的结果?