The code is:
int main(){
int i=1;
int j=2;
char c='a';
int x=-1;
x=scanf("%d%d%c", &i, &j,&c);
printf("%d",x);
}
when you enter 5,6$, this output is 1. why?
The code is:
int main(){
int i=1;
int j=2;
char c='a';
int x=-1;
x=scanf("%d%d%c", &i, &j,&c);
printf("%d",x);
}
when you enter 5,6$, this output is 1. why?
The scanf
function returns because it read one field successfully. You asked it to read two integers followed by a character. It read one integer (the 5) but then choked on the comma. So one successful field means a return value of one.