鱼C论坛

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

C语言链表怎么输出第一个数组

[复制链接]
发表于 2012-12-6 16:27:14 | 显示全部楼层 |阅读模式
5鱼币
#include "stdio.h"
struct str
{
char nema[10];
int  n;
struct str *next;
}ne[3]={{"AAA",20},{"BBB",18},{"CCC",17},};
void k(struct str *c)
{
struct str *p=NULL;
p=c;
printf("%s  %d\n",p->next->nema,p->next->n);
p=p->next;
printf("%s  %d\n",p->next->nema,p->next->n);
p=p->next;
printf("%s  %d\n",p->next->nema,p->next->n);
}
int main()
{
struct str *p=NULL;
p=&ne[0];
ne[0].next=&ne[1];
ne[1].next=&ne[2];
ne[2].next=&ne[3];
ne[3].next=NULL;
k(p);
return 0;
}


怎么输出 第一个数组 内容{"AAA",20}


想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
发表于 2012-12-6 16:27:15 | 显示全部楼层
  1. #include "stdio.h"
  2. struct str
  3. {
  4. char nema[10];
  5. int  n;
  6. struct str *next;
  7. }ne[3]={{"AAA",20},{"BBB",18},{"CCC",17},};
  8. void k(struct str *c)
  9. {
  10. struct str *p=NULL;
  11. p=c;
  12. printf("%s  %d\n",p->nema,p->n);
  13. p=p->next;
  14. printf("%s  %d\n",p->nema,p->n);
  15. p=p->next;
  16. printf("%s  %d\n",p->nema,p->n);
  17. }
  18. int main()
  19. {
  20. struct str *p=NULL;
  21. p=&ne[0];
  22. ne[0].next=&ne[1];
  23. ne[1].next=&ne[2];
  24. ne[2].next=&ne[3];
  25. ne[3].next=NULL;
  26. k(p);
  27. return 0;
  28. }
复制代码
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-4-19 01:55

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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