char num1, num2;
scanf("%s %s", &num1, &num2);
printf("num1=%c, num2=%c", num1, num2);
I executed above code on Visual Studio in Mac with following cases:
Input: a b => num1=, num2=b
Input: ab c => num1=, num2=c
Input: a bc => num1=c, num2=b
Input: ab cd => num1=d, num2=c
I absolutely know the %s should be %c, but I want to know why the first argument, char num1, cannot be displayed correctly in %s.
Moreover, the value of num2 precedes num1 if we input "a bc" or "ab cd". That looks confusing.
What's the reason or mechanism in C causes these strange output? Is the result the same on your computer? I think it is more important to know the reason rather than convention.