鱼C论坛

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

关于C语言的一道题

[复制链接]
发表于 2013-12-10 14:06:46 | 显示全部楼层 |阅读模式
10鱼币
图片上传不了,题在http://zhidao.baidu.com/question/680208439553523772.html

最佳答案

查看完整内容

你还是至尊会员?!好好去学习吧。
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2013-12-10 14:06:47 | 显示全部楼层
你还是至尊会员?!好好去学习吧。
  1. #include<stdio.h>
  2. #include<ctype.h>
  3. #include<stdlib.h>

  4. typedef struct stu
  5. {
  6.         char name[10];
  7.         char address[10];
  8.         char phone[15];
  9.         struct stu* next;
  10. }node;

  11. void init(node** head)
  12. {
  13.         (*head)=(node*)malloc(sizeof(node));
  14.         (*head)->next=NULL;
  15. }

  16. void creat(node** head)
  17. {
  18.         node *p,*q;
  19.         char ch;
  20.         p=(*head);
  21.         printf("name address phone:\n");
  22.        
  23.         q=(node*)malloc(sizeof(node));
  24.         scanf("%s %s %s",q->name,q->address,q->phone);
  25.        
  26.         q->next = p->next;
  27.         p->next = q;
  28. }

  29. void output( node n )
  30. {
  31.         node *tmp , *middle;
  32.         tmp = n.next;
  33.        
  34.         while( tmp )
  35.         {
  36.                 printf("name:%s address:%s phone:%s\n" , tmp->name , tmp->address , tmp->phone );
  37.                 middle = tmp;
  38.                 tmp = tmp->next;
  39.                 free(middle);
  40.         }
  41.         free( &n );
  42. }

  43. int main()
  44. {
  45.         node* n;
  46.         int i = 5;
  47.         init(&n);
  48.         while( i-- )
  49.         {
  50.                 creat(&n);
  51.         }
  52.         output(*n);
  53.         return 0;
  54. }
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2013-12-11 11:28:07 | 显示全部楼层
没人回答么
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2025-4-18 02:43

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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