int main(void)
{
char str[11], a;
char *string = str;
printf("Enter a first and last name: ");
scanf("%1c", &a);
fgets(string, 10, stdin);
printf("%s, %1c.", string, a);
return 0;
}
//Input Data:
//Ray Santos
//========================================
//想得到的答案
//Enter a first and last name:
//Santos, R.
//========================================
//此程式輸出的結果
//Enter a first and last name:
//ay Santos
//, R.
#include <stdio.h>
#define STRLEN 20
int main(void)
{
char str[STRLEN], a;
printf("Enter a first and last name: ");
fgets(str, sizeof(str), stdin);
printf("\n");
//顯示 Last name ==> 從空格以後才顯示出來
_Bool bprint = 0;
int i=0;
while ((i<STRLEN)&&(str[i] != '\n')) {
if (bprint) {
printf("%c", str[i]);
} else {
if (str[i]==' ') {
bprint = 1;
}
}
i++;
}
//顯示 First name 縮寫 ==> 顯示第一個字元
printf(", %1c.", str[0]);
return 0;
}