0
的工作空间,我有一些问题与C.sscanf的不是从标准
我的程序
#include <stdio.h>
#include <stdlib.h>
int main(){
char str[50];
int y=0, x=0;
printf("Insert string: ");
scanf("%s", str);
sscanf(str, "%d %d", &x, &y);
printf("x:%d y:%d\n",x,y);
return 0;
}
输入sscanf函数
10 20
输出
x:10 y:0
我也试过
sscanf(str, "%d%d", &x, &y);
和
sscanf(str, "%d%*[ \n\t]%d", &x, &y);
但输出是一样的。
奇怪的是,当我尝试
#include <stdio.h>
#include <stdlib.h>
int main(){
char str[] = "10 20";
int y=0, x=0;
sscanf(str, "%d %d", &x, &y);
printf("x:%d y:%d\n",x,y);
return 0;
}
我的输出是x:10 y:20
如果你的输出'str'了'后的scanf( “%s” 时,STR);',你会发现poblem。 – WhatsUp
'%s'停止在第一个空格字符处读取输入。 –