鱼C论坛

 找回密码
 立即注册
查看: 1261|回复: 2

用的是dev c++不知道这些问题怎么解决大佬教教我

[复制链接]
发表于 2023-10-6 12:21:19 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x

  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. #include<malloc.h>
  4. #include<string.h>
  5. #define len sizeof(struct student)
  6. #define file_data_path "student.txt"
  7. struct student
  8. {
  9.         long int num;
  10.         char name[20];
  11.         int age;
  12.         char sex[10];
  13.         char birthday[10];
  14.         char address[30];
  15.         long int tele_num;
  16.         struct student*next;
  17. };
  18. int total_num=0;
  19. struct student*head=NULL;       
  20. void welcome();
  21. void mainmenu();
  22. void record();
  23. void insertlink(struct student*stu);
  24. void insertlink1();
  25. void display(struct student*stu);
  26. void displayall();
  27. void query();
  28. void locate_num();
  29. void locate_name();
  30. void readdata();
  31. void writedate();
  32. void dellink();
  33. void change();
  34. void devise(struct student*p);
  35. int main()
  36. {
  37.         char username[9];
  38.         char userpwd[7];
  39.         int i;
  40.         welcome();
  41.         for(i=0;i<3;i++)
  42.         {
  43.                 printf("\n管理员初始用户名与密码为123\n");
  44.                 printf("请输入您的用户名");
  45.                 scanf("%s",username);
  46.                 printf("\n请输入您的密码\n") ;
  47.                 scanf("%s",userpwd);
  48.                 if((strcmp(username,"123")==0)&&(strcmp(userpwd,"123")==0))
  49.                 {
  50.                         mainmenu();
  51.                         break;
  52.                        
  53.                 }
  54.                 else
  55.                 {
  56.                         if(i<3)
  57.                         {
  58.                                 printf("用户名或密码错误,请重新输入!");
  59.                         }
  60.                         else
  61.                         {
  62.                                 printf("您已经连续三次输入错误,请明天再次输入");
  63.                          }
  64.                 }
  65. }
  66. return 0;
  67.   
  68. }
  69. void welcome()
  70. {
  71.         printf("\t\t\t+--------------------------+\n");
  72.         printf("\t\t\t||\n");
  73.         printf("\t\t\t|欢迎使用学生信息管理系统|\n");
  74.         printf("\t\t\t||\n");
  75.         printf("\t\t\t+--------------------------+\n");
  76.         printf("\n\n\n\n\n\n\n\n");
  77.         printf("\t\t\t本程序为线性表");
  78. }
  79. void mainmenu()
  80. {
  81.         int choice;
  82.         choice=-1;
  83.         readdata();
  84.         printf("\n温馨提示:为保证您的操作得到保存,请按照正常顺序退出程序^_^\n");
  85.         do{
  86.        
  87.                 printf("\n\n\n");
  88.                 printf("\t\t\t-------------------------- —\n");
  89.                 printf("\t\t\t|学生信息管理系统|\n");
  90.                 printf("\t\t\t-------------------------- —\n");
  91.                 printf("\t\t\t|[1]---录入学生信息|\n");
  92.                 printf("\t\t\t|[2]---浏览学生信息|\n");
  93.                 printf("\t\t\t|[3]---查询学生信息|\n");
  94.                 printf("\t\t\t|[4]---删除学生信息|\n");
  95.                 printf("\t\t\t|[5]---修改学生信息|\n");
  96.                 printf("\t\t\t|[6]---插入学生信息|\n");
  97.                 printf("\t\t\t|[0]---退出系统|\n");
  98.                 printf("\t\t\t*·*·*·*·*·*·*·*·*·*·*·*·*·*·*·*·") ;
  99.                 printf("\t\t\t-------------------------- —\n");
  100.                 printf("请输入你的选择");
  101.                 scanf("%d",&choice);
  102.                 switch(choice)
  103.                 {
  104.                         case 0:
  105.                         writedate();
  106.                         exit(0);
  107.                         case 1:
  108.                         record();
  109.                         break;
  110.                         case 2:
  111.                 displayall();
  112.                         break;
  113.                         case 3:
  114.                         query();
  115.                         break;
  116.                         case 4:
  117.                         dellink();
  118.                         break;
  119.                         case 5:
  120.                         change();
  121.                         break;
  122.                         case 6:
  123.                         insertlink1();
  124.                         break;
  125.                         default:
  126.                         printf("\n无效选项!");
  127.                         break;
  128.                 }                                                       
  129.         }
  130.         while(choice!=0);
  131. }
  132. void record()
  133. {
  134.         struct student*p0;
  135.         p0=(struct student* )malloc(len) ;
  136.         printf("请输入学生学号:");
  137.         scanf("%ld",&p0->num);
  138.         printf("请输入学生姓名");
  139.         scanf("%ld",&p0->name);
  140.         printf("请输入学生年龄:");
  141.         scanf("%ld",&p0->sex);
  142.         printf("请输入学生性别:");
  143.         scanf("%ld",&p0->birthday);
  144.         printf("请输入学生出生日期:");
  145.         scanf("%ld",&p0->address);
  146.         printf("请输入学生地址:");
  147.         scanf("%ld",&p0->num);
  148.         printf("请输入学生电话:");
  149.         scanf("%ld",&p0->tele_num);
  150.         insertlink(p0);
  151.         printf("该学生的信息为:\n");
  152.         printf("--------------------------------------------------");
  153.         printf("学号\t姓名\t年龄\t性别\t出身日期\t地址\t电话\n");
  154.         display(p0);
  155.        
  156.         }
  157. void inserlink(struct student*stu)
  158. {
  159.         struct student*p0,*p1,*p2;
  160.         p1=head;
  161.         p0=stu;
  162.         if(head==NULL)
  163.         {
  164.                 head=p0;
  165.                 p0->next=NULL;
  166.         }
  167.         else{
  168.                 while((p0->num>p1->num)&&(p1->next!=NULL))
  169.                 {
  170.                 p2=p1;
  171.                 p1=p1->next;                               
  172.                 }
  173.                 if(p0->num<=p1->num)
  174.                 {
  175.                         if(head==p1)
  176.                                 head=p0;
  177.                         else
  178.                                 p2->next=p0;
  179.                         p0->next=p1;
  180.                 }
  181.                 else
  182.                 {
  183.                         p1->next=p0;
  184.                         p0->next=NULL;
  185.                        
  186.                 }               
  187.         }
  188.         total_num++;
  189. }
  190. void inserlink1()
  191. {       
  192. record();       
  193. }
  194. void display(struct student*p)
  195. {
  196.         printf("%ld\t%s\t%d\t%s\t%s\t%s\t%ld\n",p->num,p->name,p->age,p->sex,p->birthday,p->address,p->tele_num);
  197.         //查看学生信息
  198. }
  199. void displayall()
  200. {
  201.         struct student*p;
  202.         p=head;
  203.         if(head!=NULL)
  204.         {
  205.                 printf("\n学号\t姓名\t年龄\t性别\t出身日期\t地址\t电话\n");
  206.                 printf("--------------------------------------------------");
  207.                 do
  208.                 {
  209.                         display(p);
  210.                         p=p->next;
  211.                 }
  212.                 while(p!=NULL);
  213.          }
  214.          printf("\n");
  215.          
  216. }
  217. void query()
  218. {
  219.         int choice;
  220.         choice=-1;
  221.         do
  222.         {

  223.         printf("\n");
  224.         printf("+---------------—+\n");
  225.         printf("|[1]---按学号查询|\n");
  226.         printf("|[2]---按姓名查询|\n");
  227.         printf("|[0]---取消|\n");       
  228.     printf("+---------------—+\n");       
  229.         printf("请输入您的选择:");
  230.         scanf("%d",&choice);       
  231.                 switch(choice)
  232.         {
  233.                 case 0:
  234.                         return;
  235.                 case 1:
  236.                         locate_num();
  237.                         break;
  238.                 case 2:
  239.                 locate_name()        ;
  240.                 break;
  241.                 default:
  242.                         printf("\n无效选项");
  243.                         break;
  244.         }
  245.         }
  246.         while(choice!=0);
  247. }
  248. void locate_num()
  249. {
  250.         int num;
  251.         struct student*p1;
  252.         printf("请输入学生学号:");
  253.         scanf("%ld",&num);
  254.         if(head==NULL)
  255.         {
  256.                 printf("无学生记录!");
  257.                 return;
  258.          }
  259.          p1=head;
  260.          while(num!=p1->num&&p1->next!=NULL)
  261.                 p1=p1->next;
  262.                 if(num==p1->num){
  263.        
  264.                 printf("\n学号\t姓名\t年龄\t性别\t出身日期\t地址\t电话\n");
  265.                 printf("--------------------------------------------------");
  266.                 display(p1);
  267.                         }
  268.                 else
  269.                 printf("没有该学生的记录,请核对");
  270. }

  271. void locate_name()
  272. {
  273.         char name[20];
  274.         struct student*p1;
  275.         printf("请输入学生姓名:");
  276.         scanf("&s",name);
  277.         if(head==NULL)
  278.         {
  279.                 printf("无学生记录\n");
  280.                 return;
  281.          
  282.          }
  283.         p1=head;
  284.         while(strcmp(name,p1->name)&&p1->next!=NULL)
  285.         p1=p1->next;
  286.         if(!strcmp(name,p1->name))
  287.         {
  288.                 printf("\n学号\t姓名\t年龄\t性别\t出身日期\t地址\t电话\n");
  289.                 printf("--------------------------------------------------");
  290.                 display(p1);
  291.          }
  292.          else
  293.          printf("没有该学生记录,请核对!");
  294. }
  295. void writedate()
  296. {
  297.         FILE*fp;
  298.         struct student*p;
  299.         fp=fopen(file_data_path,"w");
  300.         if(! fp)
  301.         {
  302.                 printf("文件打开错误");
  303.                 return;
  304.          }
  305.          fprintf(fp,"%d\n",total_num);
  306.          for(p=head;p!=NULL;p=p->next)
  307.          {
  308.                  fprintf(fp,"%ld\t%s\t%d\t%s\t%s\t%s\t%ld\n",p->num,p->name,p->age,p->sex,p->birthday,p->address,p->tele_num);
  309.          }
  310.          fclose(fp);
  311. }
  312. void readdate()
  313. {
  314.         FILE*fp;
  315.         struct student*p1,*p2;
  316.         fp=fopen(file_data_path,"r");
  317.         if(!fp)
  318.         {
  319.                 printf("文件打开错");
  320.                  return;
  321.          }
  322.         fscanf(fp,"%ld\t%s\t%d\t%s\t%s\t%s\t%ld\n",&p1->num,p1->name,p1->age,p1->sex,p1->birthday,p1->address,&p1->tele_num);
  323.         while(!feof(fp))
  324.         {
  325.                 p1=(struct student*)malloc(len);
  326.                 fscanf(fp,"%ld\t%s\t%d\t%s\t%s\t%s\t%ld\n",&p1->num,p1->name,p1->age,p1->sex,p1->birthday,p1->address,&p1->tele_num);
  327.         p2->next=p1;
  328.         p2=p1;
  329.         }
  330.         p2->next=NULL;
  331.                 fclose(fp);
  332.                
  333. }
  334. void dellink()
  335. {
  336.         struct student*p1,*p2;
  337.         long int num;
  338.         if(head==NULL)
  339.         {
  340.                 printf("无学生记录!\n");
  341.                 return;
  342.         }
  343.         printf("请输入您要删除的学生学号:");
  344.         scanf("%ld",&num);
  345.         p1=head;
  346.         while(num!=p1->num&&p1->next!=NULL)
  347.         {
  348.                 p2=p1;
  349.                 p1=p1->next;
  350.         }
  351.         if(num==p1->num)
  352.         {
  353.                 if(p1==head)
  354.                         head=p1->next;
  355.                 else
  356.                         p2->next=p1->next;
  357.                 free(p1);
  358.                 total_num--;
  359.         }
  360.         else
  361.         printf("没有该学生的记录,请核对\n");
  362.          
  363. }
  364. void change()
  365. {
  366.         struct student*p1,*p2;
  367.         long int num;
  368.         if(head==NULL)
  369.         {
  370.                 printf("无学生记录!\n");
  371.                 return;
  372.          }
  373.          printf("请输入您要修改的学生学号:\n");
  374.          scanf("%ld",&num);
  375.          p1=head;
  376.          while(num!=p1->num&&p1->next!=NULL)
  377.          {
  378.                  p2=p1;
  379.                  p1=p1->next;
  380.                 
  381.          }
  382.          if(num==p1->num)
  383.                  devise(p1);
  384.         else
  385.         printf("没有该学生记录,请核对!\n");
  386. }
  387. void devise(struct student*p)
  388. {
  389.         int choice;
  390.         choice=-1;
  391.         do
  392.         {
  393.                 printf("请输入您要修改的学生的信息内容:\n");
  394.                 printf("+----------------------+");
  395.                 printf("|姓名 请按1|\n");
  396.                 printf("|年龄 请按2|\n");
  397.                 printf("|性别 请按3|\n");
  398.             printf("|生日 请按4|\n");
  399.                 printf("|地址 请按5|\n");
  400.                 printf("|电话 请按6|\n");
  401.                 printf("|取消 请按0|\n");               
  402.                 printf("+----------------------+");
  403.                 printf("请输入您的选择:");
  404.                 scanf("%d",&choice);
  405.                 switch(choice)
  406.                 {
  407.                  case 0:
  408.                          return;
  409.                 case 1:
  410.                          printf("请输入要修改的姓名:");
  411.                          scanf("%s",p->name);
  412.                          break;
  413.                 case 2:       
  414.                         printf("请输入要修改的年龄:");
  415.                         scanf("%d",&p->age);
  416.                         break;
  417.                 case 3:
  418.                         printf("请输入要修改的性别:");
  419.                         scanf("%s",p->sex);
  420.                         break;
  421.                 case 4:
  422.                         printf("请输入要修改的生日:");
  423.                         scanf("%s",p->birthday);
  424.                         break;
  425.                 case 5:
  426.                         printf("请输入要修改的地址:");
  427.                         scanf("%s",p->address);
  428.                         break;
  429.                 case 6:
  430.                         printf("请输入要修改的电话:");
  431.                         scanf("%ld",&p->tele_num);
  432.                         break;
  433.                 default:
  434.                         printf("\n无效选项!");
  435.                         break;
  436.                          
  437.                 }                               
  438.         }
  439.         while(choice!=0);
  440. }
复制代码
1696565602826.jpg
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2023-10-6 12:35:16 | 显示全部楼层
Mike_python小 发表于 2023-10-6 12:21
I apologize, but I am an AI language model and do not have real-time information. My responses are b ...

小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2023-10-7 00:03:07 | 显示全部楼层
  1. undefined referrence
复制代码


说明你在程序中没有定义这些函数。

可以自己仔细的看一看,应该能发现拼写的错误。
(在函数名中找)
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-4-22 08:04

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表