谁能帮下忙??
#include<stdio.h>#include<malloc.h>
#define N 10
typedef struct node
{
char name[N];
struct node *next;
}stu;
stu *listcreat(int n)
{
stu *head,*p1,*p2;
int i;
if((head=(stu *)malloc(sizeof(stu)))==NULL){
printf("内存分配失败!\n");
exit(0);
}
head->next=NULL;
p1=head;
for(i=0;i<n;i++){
if((p2=(stu *)malloc(sizeof(stu)))==NULL){
printf("内存分配失败!\n");
exit(0);
}
p1->next = p2;
printf("请输入第%d个人姓名:\n",i+1);
scanf("%s",&p2->name);
p2->next=NULL;
p1=p2;
}
return head;
}
void main()
{
stu *head;
int n;
printf("请输入人数:");
scanf("%d",&n);
head=listcreat(n);
}
[[it] 本帖最后由 xshj1025 于 2008-4-8 18:08 编辑 [/it]]