This code will shows a strange output when run it.Why?
Look at the "strcat" function and "puts" function.These function need string variable.But "getchar" function read a character only,lacking '\0' character.The char array of "a,b,c" did not initialization.So the input is not a string.The variable type is not match.The code as follows:
#include"stdio.h"
#include"stdlib.h"
int main(void){
char a[23];
char b[33];
char c[22];
a[0]=getchar();
b[0]=getchar();
c[0]=getchar();
strcat(a,b);
strcat(a,c);
puts(a);
puts(b);
puts(c);
return 0;
}
The modified as follows:
#include"stdio.h"
#include"stdlib.h"
int main(void){
char a[23]="qwe";
char b[33]="rty";
char c[22]="uio";
a[0]=getchar();
b[0]=getchar();
c[0]=getchar();
strcat(a,b);
strcat(a,c);
puts(a);
puts(b);
puts(c);
return 0;
}