user-0 提问: 新人求问  程序写到一半  调试模块时遇到了始终无法解决的问题

回复:
user: user-1
content: #include<stdio.h> #include<stdlib.h> #include<string.h> #include<conio.h>  int n;  typedef struct student {     int xuehao;     char xingming[20];     char xingbie[5];     int nianling;     int chengji[3];     int pingjuncj;     int mingci;     struct student *next; }stu;  struct student* head=NULL,*p1,*p2,*p;  struct student* find(stu *f,int num) {     stu *l;     l=f;     while(l) {         if(l->xuehao==num)             break;         l=l->next;     }     return l; }  void cjlr() {     int i = 1;     printf("------------------------学生成绩录入------------------------\n\n");     p1 = (struct student *) malloc(sizeof (struct student));     printf("请输入第%d位学生信息:(输入0结束输入)\n",i++);     printf("\t学号:");scanf("%d",&p1->xuehao);     if(p1->xuehao==0)     {         printf("成绩录入结束,按任意键返回上一层");         free(p1);         return;     }     printf("\t姓名:");scanf("%s",&p1->xingming);     printf("\t性别:");scanf("%s",&p1->xingbie);     printf("\t年龄:");scanf("%d",&p1->nianling);     printf("\t高数成绩:");scanf("%d",&p1->chengji[0]);     printf("\t英语成绩:");scanf("%d",&p1->chengji[1]);     printf("\t程序成绩:");scanf("%d",&p1->chengji[2]);      while (1)     {         n++;         if(n==1)             head = p1;         else             p2->next = p1;          p2 = p1;         p1 = (struct student *) malloc(sizeof (struct student));         printf("请输入第%d位学生信息:\n",i++);         printf("\t学号:");scanf("%d",&p1->xuehao);         if(p1->xuehao==0)         {             printf("成绩录入结束,按任意键返回上一层");             break;         }         printf("\t姓名:");scanf("%s",&p1->xingming);         printf("\t性别:");scanf("%s",&p1->xingbie);         printf("\t年龄:");scanf("%d",&p1->nianling);         printf("\t高数成绩:");scanf("%d",&p1->chengji[0]);         printf("\t英语成绩:");scanf("%d",&p1->chengji[1]);         printf("\t程序成绩:");scanf("%d",&p1->chengji[2]);     }     free(p1);     p2->next = NULL;     printf("\n\n成绩录入成功！");      system("cls"); }  void cjcx() {     if(head==NULL)     {         printf("学生信息尚未录入，请在录入后查询");         return;     }     int num;     printf("------------------------学生成绩查询------------------------\n\n");     printf("\n请输入您要查询的学生学号:   ");     scanf("%d",&num);     p = find(head,num);     if (p) {         printf("\n学号\t姓名\t性别\t年龄\t高数\t英语\t程序\n\n");         printf("%d\t%s\t%s\t%d\t%d\t%d\t%d\n",p->xuehao,p->xingming,p->xingbie,p->nianling,p->chengji[0],p->chengji[1],p ->chengji[2]);     } else {         printf("学号%d未找到",num);     }     printf("\n\n按任意键返回上一层");    getch();    system("cls"); } void cjtj() {  }  void cjsc() {  }  void cjxg() {  }  void cjbc() {  }  void cjjz() {  }  int main() { ss:int i,choose;    for(i=1;i<=60;i++)    {        printf("=");    }    printf("\n\n");    printf("----------------------学生成绩查询系统----------------------\n\n");    printf("\n\t1.成绩录入\n");    printf("\n\t2.成绩查询\n");    printf("\n\t3.成绩添加\n");    printf("\n\t4.成绩删除\n");    printf("\n\t5.成绩修改\n");    printf("\n\t6.成绩保存\n");    printf("\n\t7.成绩加载\n");    printf("\n\t8.退出系统\n");    printf("\n\n");    for(i=1;i<=60;i++)    {        printf("=");    }    printf("\n请选择您要执行的功能:  "); AA:scanf("%d",&choose);    switch (choose)    {        case 1: { system("cls");  cjlr();goto ss;break;}        case 2: { system("cls");  cjcx();goto ss;break;}        case 3: { system("cls");  cjtj();break;}        case 4: { system("cls");  cjsc();break;}        case 5: { system("cls");  cjxg();break;}        case 6: { system("cls");  cjbc();break;}        case 7: { system("cls");  cjjz();break;}        case 8: {   break;}        default:{printf("输入错误请重试:  ");goto AA;}    }    return 0; } 参考一下吧，能不用goto语句就不要用goto语句，因为goto的代码不易阅读；相当于给自己找麻烦  find的问题主要是在创建链表时没有指定尾部的NULL;

user: user-0
content: 引用 1 楼 自信男孩的回复:#include<stdio.h> #include<stdlib.h> #include<string.h> #include<conio.h>  int n;  typedef struct student {     int xuehao;     char xingming[20];     char xingbie[5];     int nianling;     int chengji[3];     int pingjuncj;     int mingci;     struct student *next; }stu;  struct student* head=NULL,*p1,*p2,*p;  struct student* find(stu *f,int num) {     stu *l;     l=f;     while(l) {         if(l->xuehao==num)             break;         l=l->next;     }     return l; }  void cjlr() {     int i = 1;     printf("------------------------学生成绩录入------------------------\n\n");     p1 = (struct student *) malloc(sizeof (struct student));     printf("请输入第%d位学生信息:(输入0结束输入)\n",i++);     printf("\t学号:");scanf("%d",&p1->xuehao);     if(p1->xuehao==0)     {         printf("成绩录入结束,按任意键返回上一层");         free(p1);         return;     }     printf("\t姓名:");scanf("%s",&p1->xingming);     printf("\t性别:");scanf("%s",&p1->xingbie);     printf("\t年龄:");scanf("%d",&p1->nianling);     printf("\t高数成绩:");scanf("%d",&p1->chengji[0]);     printf("\t英语成绩:");scanf("%d",&p1->chengji[1]);     printf("\t程序成绩:");scanf("%d",&p1->chengji[2]);      while (1)     {         n++;         if(n==1)             head = p1;         else             p2->next = p1;          p2 = p1;         p1 = (struct student *) malloc(sizeof (struct student));         printf("请输入第%d位学生信息:\n",i++);         printf("\t学号:");scanf("%d",&p1->xuehao);         if(p1->xuehao==0)         {             printf("成绩录入结束,按任意键返回上一层");             break;         }         printf("\t姓名:");scanf("%s",&p1->xingming);         printf("\t性别:");scanf("%s",&p1->xingbie);         printf("\t年龄:");scanf("%d",&p1->nianling);         printf("\t高数成绩:");scanf("%d",&p1->chengji[0]);         printf("\t英语成绩:");scanf("%d",&p1->chengji[1]);         printf("\t程序成绩:");scanf("%d",&p1->chengji[2]);     }     free(p1);     p2->next = NULL;     printf("\n\n成绩录入成功！");      system("cls"); }  void cjcx() {     if(head==NULL)     {         printf("学生信息尚未录入，请在录入后查询");         return;     }     int num;     printf("------------------------学生成绩查询------------------------\n\n");     printf("\n请输入您要查询的学生学号:   ");     scanf("%d",&num);     p = find(head,num);     if (p) {         printf("\n学号\t姓名\t性别\t年龄\t高数\t英语\t程序\n\n");         printf("%d\t%s\t%s\t%d\t%d\t%d\t%d\n",p->xuehao,p->xingming,p->xingbie,p->nianling,p->chengji[0],p->chengji[1],p ->chengji[2]);     } else {         printf("学号%d未找到",num);     }     printf("\n\n按任意键返回上一层");    getch();    system("cls"); } void cjtj() {  }  void cjsc() {  }  void cjxg() {  }  void cjbc() {  }  void cjjz() {  }  int main() { ss:int i,choose;    for(i=1;i<=60;i++)    {        printf("=");    }    printf("\n\n");    printf("----------------------学生成绩查询系统----------------------\n\n");    printf("\n\t1.成绩录入\n");    printf("\n\t2.成绩查询\n");    printf("\n\t3.成绩添加\n");    printf("\n\t4.成绩删除\n");    printf("\n\t5.成绩修改\n");    printf("\n\t6.成绩保存\n");    printf("\n\t7.成绩加载\n");    printf("\n\t8.退出系统\n");    printf("\n\n");    for(i=1;i<=60;i++)    {        printf("=");    }    printf("\n请选择您要执行的功能:  "); AA:scanf("%d",&choose);    switch (choose)    {        case 1: { system("cls");  cjlr();goto ss;break;}        case 2: { system("cls");  cjcx();goto ss;break;}        case 3: { system("cls");  cjtj();break;}        case 4: { system("cls");  cjsc();break;}        case 5: { system("cls");  cjxg();break;}        case 6: { system("cls");  cjbc();break;}        case 7: { system("cls");  cjjz();break;}        case 8: {   break;}        default:{printf("输入错误请重试:  ");goto AA;}    }    return 0; } 参考一下吧，能不用goto语句就不要用goto语句，因为goto的代码不易阅读；相当于给自己找麻烦  find的问题主要是在创建链表时没有指定尾部的NULL; 啊。没注意到尾节点的null。好吧，谢谢了，这种程序如果不用goto也能实现模块之间的跳转吗