好友
阅读权限10
听众
最后登录1970-1-1
|
#include <stdio.h>
struct birthday{
int year;
int month;
int day;
};
struct student{
int id;
char * name;
struct birthday b;
struct student * next;
};
void outpt( struct student * p ) {
while (p->next != NULL){
printf("id=%d name:%s birthday:%d,%d,%d\n",
p->id, p->name, p->b.year, p->b.month, p->b.day);
p->next = p->next->next;
}
}
int main() {
struct student stu[] = {{1, "zhangsan", {1990, 1, 1}, NULL},
{2, "lisi", {2000, 2, 2}, NULL},
{3, "wangwu", {1992, 3, 3}, NULL},
{4, "zhaoliu", {1989, 4, 4}, NULL},
{5, "maqi", {1995, 5, 5}, NULL}};
stu[0].next = &stu[1];
stu[1].next = &stu[2];
stu[2].next = &stu[3];
stu[3].next = &stu[4];
struct student * pstu = stu;
outpt(pstu);
return 0;
}
不能遍历这个链表,好像是指针进不了stu[1],请问是哪的问题? |
|
发帖前要善用【论坛搜索】功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。 |
|
|
|
|