#include<stdio.h>
#include<malloc.h>
#include <conio.h>
/**************************************************************/
struct student
{
int num;
struct student *next;
};
/************************创建链表****************************/
struct student *create()
{
struct student *head;
head=(struct student *)malloc(sizeof(struct student));
head->next=NULL;
return head;
}
/************************录入数据******************************/
void Input(struct student *h)
{
struct student *p,*last=h;
while(1)
{
p=(struct student *)malloc(sizeof(struct student));
printf("请输入学生学号:");scanf("%d",&p->num);
p->next=NULL;
last->next=p;last=p;
int ch;
printf("要继续输入下一个吗(y/n)");ch=getch();
if(ch=='y'||ch=='Y')
{
}
else
{
free(p);
break;
}
}
}
/************************显示链表******************************/
void Disp(struct student *h)
{
printf("\n\n");
struct student *p=h;
while(p->next!=NULL)
{
p=p->next;
printf("学号为:%d\n",&p->num);
}
}
/***************************************************************/
void main()
{
struct student *h;
h=create();
Input(h);
Disp(h);
}
/***************************************************************/
为什么老是出错??
[此贴子已经被作者于2007-7-22 20:40:04编辑过]