读书人

c语言链表源程序求各位大牛帮小弟找

发布时间: 2012-03-21 13:33:15 作者: rapoo

c语言链表源程序,求各位大牛帮小弟找找错
# include <stdio.h>
# include <string.h>
# define NUM 10

struct student
{
int num;
int age;
char name[20];
struct student *next;
}

int main(void)
{
int i;
int e;
int *head, *p;
struct student st[NUM];

printf("Please input Name Num Age\n");

for(i = 0; i < NUM; i++)
{
fgets(st[i].name, NUM, stdin);

scanf(" %d %s %d", &st[i].num, &st[i].age);
}

head = &st[0].num;
p = head;
st[NUM-1].next = NULL;

printf("Please input a number: ");
scanf(" %d", &e);

for(i = 0; i < NUM, p != NULL; i++)
{
if(e == st[i].num)
{
printf("The nunber, name and age is %d, %s, %d\n",st[i].num,
st[i].name, st[i].age );
}
else
{
p -> next = st[i+1].num;
}
}

return 0;
}

[解决办法]
1.结构体struct定以后要使用;
struct student
{
int num;
int age;
char name[20];
struct student *next;
};

2.
*p = st[i+1].num;


读书人网 >C语言

热点推荐