关于链表的求助
#include <stdio.h>#include <stdlib.h>
typedef struct stud
{
char name[10];
int num;
struct stud *next;
}STU;
void InitList(STU *p)
{
p = NULL;
}
void InsertList(STU *p)
{
STU *newp, *cur;
char strTmp[10];
newp = (STU *)malloc(sizeof(STU));
puts("请输入学生信息:");
printf("\t学生姓名:");
gets(newp->name);
printf("\n\t学生学号:");
gets(strTmp);
newp->num = atol(strTmp);
newp->next = NULL;
if (p==NULL)
{
p = newp;
}
else
{
cur = p;
while (cur->next)
{
cur = cur->next;
}
cur->next = newp;
}
}
void PrintList(STU *p)
{
STU *cur;
int i = 1;
if (p==NULL)
{
puts("链表为空!");
return;
}
else
{
cur = p;
do
{
printf("第%d个学生信息如下:", i);
printf("\n\t学生姓名: %s", cur->name);
printf("\n\t学生学号: %ld", cur->num);
cur = cur->next;
} while (cur);
}
}
int main()
{
STU s;
InitList(&s);
InsertList(&s);
puts("============");
PrintList(&s);
return 0;
}
编译没问题 ,运行出错