鱼C论坛

 找回密码
 立即注册
查看: 1830|回复: 1

求助!程序运行,输入数据后,打印操作跳过了,看不出什么问题

[复制链接]
发表于 2019-7-17 15:20:32 | 显示全部楼层 |阅读模式

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

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

x
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. #include<string.h>
  4. struct student
  5. {
  6.     int num;
  7.     int score;
  8.     struct student *next;
  9. };
  10. struct student *chuangjian() {
  11.     struct student *head;
  12.     struct student *p1, *p2;
  13.     head = (struct student*)malloc(sizeof(struct student));
  14.     int n;
  15.     head->next = NULL;
  16.     p2 = head;
  17.     printf("input the num:");
  18.     scanf("%d", &n);
  19.     while(n != 0) {
  20.         p1 = (struct student*)malloc(sizeof(struct student));
  21.         p1->num = n;
  22.         printf("input the score:");
  23.         scanf("%d", &p1->score);
  24.         printf("\n");
  25.         p1->next = NULL;

  26.         p1 = p1->next;
  27.         p2 = p1;
  28.         printf("input the num:");
  29.         scanf("%d", &n);
  30.     }

  31.     return head;
  32. }


  33. void print(struct student *head)
  34. {
  35.         struct student *a;
  36.         a=head->next;
  37.         while(a)
  38.         {printf("%d\t%d\n",a->num,a->score);
  39.         a->next=a;}

  40. }
  41. struct student *del(struct student *head, int num) {
  42.     struct student *p1, *p2;
  43.     if(head = NULL) {
  44.         printf("\nthis is null!\n");
  45.         goto END;
  46.     }
  47.     p1 = head;
  48.     while(p1->num != num && p1->next != NULL) {
  49.         p2 = p1;
  50.         p1 = p1->next;
  51.     }
  52.     if(num == p1->num) {
  53.         p2->next = p1->next;
  54.         printf("\nDelete num:%d succeed!\n", num);
  55.     }
  56.     else
  57.     {
  58.         printf("%d not been found!\n", num);
  59.     }
  60.     END:
  61.     return head;
  62. }
  63. int main() {
  64.     struct student *head=NULL;
  65.     int n;
  66.     head = chuangjian();
  67.     print(head);
  68.     printf("input the num for delete:");
  69.     scanf("%d", &n);
  70.     del(head, n);
  71.     return 0;
  72. }
复制代码
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2019-7-18 13:26:24 | 显示全部楼层
我运行了你的程序后没有跳过,应该是编程环境设置的问题。你可试一下system(“pause”),记得加上头文件include<windows.h>.还有程序中尽量少使用go语句,虽然编写方便,但不利于代码的复用性,对其维护困难,可读性差。
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-5-25 00:44

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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