#include<stdio.h>
#include<string.h>
int main()
{
char name[10][30];
int i,n;
printf("How many names?\n");
scanf("%d",&n);
printf("Enter names\n");
for(i=0;i<n;++i)
gets(name[i]);
printf("\n The names are\n");
for(i=0;i<n;++i)
printf("%s\n",name[i]);
}
我正在嘗試按順序對人員的全名進行排序。所以我讀取了所有名字並將其名稱存儲在一個字符串數組中。但問題是當這個程序執行時:使用獲取函數的數組中的字符串輸入
How many names
4
Enter names
john G
susan sing
puskar
The names are
john G
susan sing
puskar
我不明白爲什麼空字符串被讀取。