Every time I run this it stops working when I enter the string.I use visual studio 2013.Here's my 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 is that the
stdout
output buffer is not flushed. By defaultstdout
is line buffered meaning the output written tostdout
will not actually be output until there is a newline.So the solution is simply to write a newline:
Also note that you can't write input more than nine characters, or you will write beyond the bounds of the array
x
and have undefined behavior. The number nine comes from your array being tenchar
big, and strings in C needs an extra character to terminate the string, so the largest string you can put inx
is ten minus one.