Я хочу написать программу, которая может:
когда я вхожу, скажем " Алан Тьюринг ", он выдает " Тьюринг, A ".
Но для моей следующей программы она выдает « uring, A », я долго думал, но не смог понять, куда идет T .
Вот код:
#include <stdio.h>
int main(void)
{
char initial, ch;
//This program allows extra spaces before the first name and between first name and second name, and after the second name.
printf("enter name: ");
while((initial = getchar()) == ' ')
;
while((ch = getchar()) != ' ') //skip first name
;
while ((ch = getchar()) == ' ')
{
if (ch != ' ')
printf("%c", ch); //print the first letter of the last name
}
while((ch = getchar()) != ' ' && ch != '\n')
{
printf("%c", ch);
}
printf(", %c.\n", initial);
return 0;
}