


以下为源码(我输入的数据它输出不了,找了很久不知道哪里错,各位看看怎么改)
#include <stdio.h>
#include <stdlib.h>
struct student {
char name[20];
int number;
struct student* next;
};
int count;
struct student* creat()
{
struct student* head = NULL;
struct student* end,*new1;
count = 0;
end = new1=(struct student*)malloc(sizeof(struct student));
printf("please input you need numbers:\n");
scanf("%s", &new1->name);
scanf("%d", &new1->number);
while (new1 ->name!=0)
{
count++;
if (count == 1)
{
new1->next = head;
end = new1;
head = new1;
}
else
{
new1->next = NULL;
end->next =new1;
end = new1;
}
new1 = (struct student*)malloc(sizeof(struct student));
scanf("%s", &new1->name);
scanf("%d",&new1->number);
}
free(new1);
return head;
}
void print(struct student* head)
{
struct student* temp;
int index = 1;
printf("有%d个成员\n",count);
temp = head;
while (temp != NULL)
{
printf("the NO%d menber is:\n", index);
printf("the name is:%s\n", temp->name);
printf("the number is:%d\n", temp->number);
printf("\n");
temp = temp->next;
index++;
}
}
int main()
{
struct student* head;
head = creat();
print(head);
return 0;
}