#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