I am having trouble understanding what getchar() != ' '
and getchar() = ' '
are doing in my code.
Why do there need to be opposites.
The user may input extra spaces between the first name and last, and before the first name and after the last name.
#include <stdio.h>
int main(void) {
char c, initial;
printf("Enter a first and last name: ");
scanf(" %c", &initial);
printf("%c\n", initial);
while ((c = getchar()) != ' ')
;
while ((c = getchar()) == ' ')
;
do {
putchar(c);
} while ((c = getchar()) != '\n' && c != ' ');
printf(", %c.\n", initial);
return 0;
}