I have some issue with sscanf function in C.
My program
#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;
}
Input
10 20
Output
x:10 y:0
I also tried
sscanf(str, "%d%d", &x, &y);
and
sscanf(str, "%d%*[ \n\t]%d", &x, &y);
but the output is the same.
The strange thing is that when I try
#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;
}
my output is x:10 y:20