Updated code:
int main()
{
char x[]="Yasser Mohamed";
char ch;
int i=0;
while (x[i]!='\0')
{
if(x[i]!=' ') {
printf("%c", x[i]); // replace putchar with printf
fflush(stdout); // force character to appear
}
i++;
}
printf("\n"); // print newline so shell doesn't appear right here
return 0 ;
}
Strings are terminated with null \0
characters not newlines.
Also, you should add an fflush
statement (at least on linux) to make sure every character gets printed.
To make your output look nice, add a newline after the loop.
I replaced your putchar
call with printf
to see if that would help when I ran your program. putchar
will likely also work fine.
I removed system(pause)
because it didn't seem to help. I added a newline character print instead.