The specific question is this: the user enters the text, for example, if the user enters
hello (spaces) (spaces) world
The output that the user gets is
hello (space) world.
The following is my code, the adjustment of the number of spaces can be achieved, I am a bit confused because my output will eat the first letter. I want to know why this will happen.
The code:
#include <stdio.h>
int main() {
int characters = 0;
while ((characters = getchar()) != EOF) {
if (characters != ' ') {
putchar(characters);
}
if (characters == ' ') {
while ((characters = getchar()) == ' ');
putchar(' ');
}
}
}
The output:
Hello world world world
Hello orld orld orld
