ljq2786430730 2021-11-06 15:26 采纳率: 100%

# 循环一次，二维动态数组就自动初始化为零，是哪里错了

``````int *ID=NULL,*In=NULL,*Exp=NULL,choice,num;
char **Name=NULL;
for(;;)
{
printf("1.Input record\n");
printf("2.Sort and list records in alphabetical order by user name\n");
printf("3.Search records by user name\n");
printf("4.Calculate and list per capita income and expenses\n");
printf("5.List records which have more expenses than per capita expenses\n");
printf("6.List all records\n");
printf("0．Exit\n");
scanf("%d",&choice);
if(choice==1)
{
int i;
printf("The number of users is ");
scanf("%d",&num);
ID=(int*)calloc(num,sizeof(int));
In=(int*)calloc(num,sizeof(int));
Exp=(int*)calloc(num,sizeof(int));
char  **Name=(char**)calloc(num,sizeof(char*));
for(i=0;i<num;i++)
{
Name[i]=(char*)calloc(N,sizeof(char));
}
Input(ID,Name,In,Exp,num);
Print(ID,Name,In,Exp,num);

}
else if(choice==2)
{

}
else if(choice==3)
{

}
else if(choice==4)
{

}
else if(choice==5)
{

}
else if(choice==6)
{

Print(ID,Name,In,Exp,num);
}
else if(choice==0)
{
int i;
free(ID);
free(In);
free(Exp);
for(i=0;i<num;i++)
{
free(Name[i]);
}
free(Name);
return 0;
}
else
{
printf("error!\n");
}
}
``````
``````
void Input(int *ID,char *Name[],int *In,int *Exp,int num)
{
int i;
for(i=0;i<num;i++)
{
scanf("%d%s%d%d",&ID[i],Name[i],&In[i],&Exp[i]);
}
printf("record end!\n");
}
``````
• 写回答

• 系统已结题 11月14日
• 已采纳回答 11月6日
• 创建了问题 11月6日

#### 悬赏问题

• ¥20 51单片机实训实验报告
• ¥15 C# 循环读写数据中途突然变慢
• ¥100 CVI2012 做暗通道图像去雾思路详细步骤
• ¥15 用Java实现双端队列
• ¥150 ID3决策树实现分类