使用链表该如何输入输出?
#include "stdio.h"#include "malloc.h"
#define NULL 0
struct student
{
int num;
int score;
struct student *next;
};
int n;
struct student * create()//这个程序为什么不能够输入和输出,代码麻烦帮我修改一下?
{
struct student a,b,c,*p,*head;
p=(struct student *)malloc(sizeof(struct student));
scanf("%d%d",&p->num,p->score);
head=NULL;
while(p->num=NULL)
{
n=n+1;
if(n==1)
head=p;
else
p->next=p;
p=(struct student *)malloc(sizeof(struct student));
scanf("%d%d",&p->num,&p->score);
}
p->next=NULL;
return (head);
}
void print(struct student *head)
{
struct student *p;
printf("\nNow,These %d records are:\n",n);
p=head;
if(head!=NULL)
{
do
{
printf("%d%d\n",p->num,p->score);
p=p->next;
}while(p!=NULL);
}
}
int main(int argc, char* argv[])
{
struct student *head;
head=create();
print(head);
return 0;
}