关于动态链表输出的疑问~
#include<stdio.h>#include<stdlib.h>
#include "string.h"
#define NULL 0
struct student
{
int num;
char name[20];
int age;
struct student *next;
};
int n;
typedef struct student st;
st* create(void)
{
st *head,*p1,*p2;
n=0;
p1=p2=(st*)malloc(sizeof(st));
scanf("%d,%s,%d",&(p1->num),p1->name,&(p1->age));
head=NULL;
while(p1->num!=0)
{
n=n+1;
if(n==1)head=p1;
else p2->next=p1;
p2=p1;
p1=(st*)malloc(sizeof(st));
scanf("%d,%s,%d",&(p1->num),p1->name,&(p1->age));
}
p2->next=NULL;
return head;
}
void print(st*head)
{
st *p;
printf("\nNow,The %d records are:\n",n);
p=head;
if(head!=NULL)
do
{
printf("%d,%s,%d\n",p->num,p->name,p->age);
p=p->next;
}while(p!=NULL);
}
void main()
{
st *head;
print(head);
}
为什么会在输出结果后面多一行随机数 求解答~
如果可以的话能不能帮我链表增加一个查询数据和修改数据的功能~
谢谢了