鱼C论坛

 找回密码
 立即注册
查看: 1127|回复: 4

[已解决]C语言

[复制链接]
发表于 2020-4-16 16:44:05 | 显示全部楼层 |阅读模式

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

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

x
  1. #include<stdio.h>
  2. #include<stdlib.h>

  3. struct stud_node
  4. {
  5.     int num;
  6.     char name[20];
  7.     int grade;
  8.     struct stud_node *next;
  9. };

  10. struct stud_node *Creat_Stud_Doc();
  11. struct stud_node * InsertDoc(struct stud_node *head,struct stud_node *p);


  12. int main()
  13. {
  14.     int choice;
  15.     struct stud_node *head;


  16.     do
  17.     {
  18.         printf("请输入您要执行的操作:");
  19.         scanf("%d",&choice);
  20.         switch(choice)
  21.         {
  22.         case 1:
  23.             head = Creat_Stud_Doc();
  24.             break;
  25.         }
  26.     }while(choice!=0);
  27. }

  28. struct stud_node *Creat_Stud_Doc()
  29. {
  30.     struct stud_node *head,*p;
  31.     int size;
  32.     int num;
  33.     char name[20];
  34.     int grade;
  35.     size = sizeof(struct stud_node);
  36.     printf("请输入学生信息:");
  37.     scanf("%d%s%d",&num,name,&grade);
  38.     head = NULL;
  39.     while(num != 0)
  40.     {
  41.         p = (struct stud_node *)malloc(size);
  42.         p ->num = num;
  43.         strcpy(p ->num,num);
  44.         p ->grade = grade;
  45.         head = InsertDoc(head,p);
  46.         scanf("%d%s%d",&num,name,&grade);
  47.     }
  48.     return head;

  49. };

  50. struct stud_node *InsertDoc(struct stud_node *head, struct stud_node *p)
  51. {
  52.     struct stud_node *str,*str1,*str2;

  53.     str = p;
  54.     str2 = head;

  55.     if(head == NULL)
  56.     {
  57.         head = str;
  58.         head ->next = NULL;
  59.     }
  60.     else
  61.     {
  62.         while((str ->num > str2 ->num) && (str2 ->next != NULL))
  63.         {
  64.             str1 = str2;
  65.             str2 = str2 ->next;
  66.         }
  67.         if(str ->num <= str2 ->num)
  68.         {
  69.             if(str2 == head)
  70.             {
  71.                 head = str;
  72.             }
  73.             else
  74.             {
  75.                 str1->next = str;
  76.             }
  77.             str->next ->str2;
  78.         }
  79.         else
  80.         {
  81.             str2 = str;
  82.             str2->next = NULL;
  83.         }
  84.     }

  85.     return head;
  86. };
复制代码



写的链表增加和插入,但是编译出错,大神帮忙看一下哪里出错?
最佳答案
2020-4-16 16:54:50
第50行,strcpy函数需要include一个库文件string.h
另外,该函数用于字符串复制,你应该是打错了,估计你是想把name复制给p->name

第88行,赋值运算符=写错了,写成  ->  了

我只看了编译错误,没有逻辑运行是否正确

这些应该能够在编译给出的错误提示中看出来啊。看不懂编译的错误提示?
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2020-4-16 16:54:50 | 显示全部楼层    本楼为最佳答案   
第50行,strcpy函数需要include一个库文件string.h
另外,该函数用于字符串复制,你应该是打错了,估计你是想把name复制给p->name

第88行,赋值运算符=写错了,写成  ->  了

我只看了编译错误,没有逻辑运行是否正确

这些应该能够在编译给出的错误提示中看出来啊。看不懂编译的错误提示?
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2020-4-16 17:36:16 | 显示全部楼层
sunrise085 发表于 2020-4-16 16:54
第50行,strcpy函数需要include一个库文件string.h
另外,该函数用于字符串复制,你应该是打错了,估计你 ...

gcc怎么看错误提示?一般用他就只给出错误的大概位置。。。
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-4-16 17:39:03 | 显示全部楼层
老牛来学习 发表于 2020-4-16 17:36
gcc怎么看错误提示?一般用他就只给出错误的大概位置。。。

呃,好吧。

若是条件允许,可以换一个编译器,对于初学者能看编译错误很重要。
若是不想换,就当我没说。
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2020-4-16 17:41:01 | 显示全部楼层
sunrise085 发表于 2020-4-16 17:39
呃,好吧。

若是条件允许,可以换一个编译器,对于初学者能看编译错误很重要。

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

使用道具 举报

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

本版积分规则

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

GMT+8, 2025-7-12 21:28

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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