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
stdoutoutput buffer is not flushed. By defaultstdoutis line buffered meaning the output written tostdoutwill 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
xand have undefined behavior. The number nine comes from your array being tencharbig, and strings in C needs an extra character to terminate the string, so the largest string you can put inxis ten minus one.