ljq2786430730 2021-11-06 15:26 采纳率: 100%
浏览 14
已结题

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

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");
printf("    Please enter your choice: ");
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++)
    {
        printf("Please input record:\n");
        scanf("%d%s%d%d",&ID[i],Name[i],&In[i],&Exp[i]);
    }
    printf("record end!\n");
}
  • 写回答

1条回答 默认 最新

  • CSDN专家-link 2021-11-06 15:28
    关注

    你说的是哪个循环?

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

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

悬赏问题

  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥20 测距传感器数据手册i2c