arrays - c reading and writing strings visual studio 2013 -
every time run stops working when enter string.i use visual studio 2013.here's code:
#include<stdio.h> #include<stdlib.h> int main(void){ char x[10]; scanf("%s",x); printf("%s",x); system("pause"); return 0; }
what probably happens stdout
output buffer not flushed. default stdout
line buffered meaning output written stdout
not output until there newline.
so solution write newline:
printf("%s\n",x);
also note can't write input more 9 characters, or write beyond bounds of array x
, have undefined behavior. number 9 comes array being ten char
big, , strings in c needs character terminate string, largest string can put in x
ten minus one.
Comments
Post a Comment