#include<stdio.h>
#include<string.h>
void main()
{
int entry,i;
printf("\nPlease indicate the number of records you want to enter :\n");
scanf("%d",entry);
char ent[entry][100000];
printf("\nPlease input records of students (enter a new line after each record), with following format first name last name score \n");
for(i=0;i<entry;i++)
{
gets(ent[i]);
printf("%s",ent[i]);
}
}
以下是接受學生數據,名字姓氏然後得分的代碼。爲什麼我會收到分段錯誤?
'scanf函數使用
malloc
得到一個數組時,你可以不知道數組的長度(「%d」,&entry);'你錯過了&符號。 – JS1 2015-03-31 02:49:39此外,大多數系統對本地陣列的大小有相當低的限制,您可能會超過它。你應該使用'malloc()'來代替。 – Barmar 2015-03-31 02:51:52
@ JS1即使在處理&符號後仍存在錯誤。謝謝 – 2015-03-31 02:52:08