早上无叶花 2016-08-16 15:10 采纳率: 33.3%
浏览 1227

解释一下链表的指针别名怎么使用?我用的有什么问题吗?怎么一直只有输出最后一个输入的字符串

1 #include
2 #include
3 #include
4
5 typedef struct node
6 {

7 char name[20];
8 struct node *plink;
9 }*p_list,NODE;
10
11 void create_node_fun(p_list *new_head)
12 {
13 int len;
14 char str_name[20];
15 p_list new_p = NULL;
16 if(*new_head == NULL)
17 {
18 printf("*new_head == NULL");
19 exit(0);
20 }
21 else
22 {
23 p_list *ptail = new_head;
24 (*ptail)->plink = NULL;
25 printf("input node len =");
26 scanf("%d",&len);
27 for(int i = 0;i < len;i ++)
28 {
29 new_p = (p_list)malloc(sizeof(NODE));
30 if(new_p == NULL)
31 {
32 printf("new_p == NULL");
33 exit(0);
34 }
35 else
36 {
37 scanf("%s",str_name);
38 strcpy(new_p->name,str_name);
39 (ptail)->plink = new_p;
40 new_p->plink = NULL;
41 ptail = new_p;
42 }
43 }
44
45 }
46
47 }
48 void printf_node_fun(p_list *new_head)
49 {
50 p_list *new_p = new_head;
51
52 while((*new_p) != NULL)
53 {
54 printf("%s\n",(*new_p)->name);
55 *new_p = (*new_p)->plink;
56 }
57 }
58 void destroy_node_fun()
59 {
60
61 }
62
63 int main()
64 {
65 p_list head = NULL;
66 head = (p_list)malloc(sizeof(NODE));
44,0-1 89%
67
68 create_node_fun(&head);
69 printf_node_fun(&head);
70 return 0;
71 }

  • 写回答

2条回答 默认 最新

  • df夜落花千树 2016-08-16 15:48
    关注

    为什么不写成类,这样写出来也不好用啊,链表我倒是经常写,但不带这么写的。

    评论

报告相同问题?

悬赏问题

  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥15 Python3.5 相关代码写作
  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗