鱼C论坛

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

c语言链表

[复制链接]
发表于 2013-9-22 07:34:47 | 显示全部楼层 |阅读模式
2鱼币
  1. #include "stdio.h"
  2. #define NULL 0
  3. struct student
  4. {
  5.         int num;
  6.         char *name;
  7.         struct student *next;
  8. };
  9. struct student *creat(struct student *head)
  10. {
  11.         struct student *pf,*pb;
  12.         int i;
  13.         for(i=0;i<2;i++)
  14.         {
  15.                 pb=(struct student * )malloc(sizeof(struct student));
  16.                 printf("请输入学号:");
  17.                 scanf("%d",&pb->num);
  18.                 printf("请输入姓名:");
  19.                 scanf("%s",&pb->name);
  20.                 if(i==0)        pf=head=pb;
  21.                 else            pf->next=pb;
  22.                 pb->next=NULL;
  23.                 pf=pb;
  24.         }
  25.         return(head);
  26. }
  27. main()
  28. {
  29.         struct student *head;
  30.         creat(head);
  31.         while(head->next!=NULL)
  32.         {
  33.                 printf("%d   %s\n",head->num,head->name);
  34.                 head=head->next;
  35.         }
  36. }
复制代码

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

使用道具 举报

发表于 2013-9-22 07:34:48 | 显示全部楼层
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #define NULL 0
  4. struct student
  5. {
  6.         int num;
  7.         char name[20];
  8.         struct student *next;
  9. };
  10. struct student *creat()
  11. {
  12.         struct student *pf,*pb,*head;
  13.         int i;
  14.         for(i=0;i<2;i++)
  15.         {
  16.                 pb=(struct student * )malloc(sizeof(struct student));
  17.                 printf("请输入学号:");
  18.                 scanf("%d",&pb->num);
  19.                 printf("请输入姓名:");
  20.                 scanf("%s",&pb->name);
  21.                 if(i==0)        
  22.                         pf=head=pb;
  23.                 else
  24.                 {
  25.                         pf->next=pb;
  26.                         pb->next=NULL;
  27.                 }
  28.                 pf=pb;
  29.         }
  30.         return(head);
  31. }
  32. void main()
  33. {
  34.         struct student *head=NULL;
  35.         head=creat();
  36.         while(head!=NULL)
  37.         {
  38.                 printf("%d   %s\n",head->num,head->name);
  39.                 head=head->next;
  40.         }
  41. }
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2013-9-22 07:35:57 | 显示全部楼层
求各位帮我看一下,为什么程序运行不起,谢了!
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2013-9-22 09:22:24 | 显示全部楼层
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2013-9-23 09:19:34 | 显示全部楼层
路过。回帖是美德。。。
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2025-11-6 17:37

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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