33,008
社区成员
发帖
与我相关
我的任务
分享
//看看哪有问题?运行的时候输入时候可以正常,输出的时候出问题了。
//当学号为0的时候停止
#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
#include <string.h>
#define NULL 0
typedef struct stu
{
long num;
char name[20];
char sex;
struct stu *next;
}*student;
void ceate(student &head)
{
student p1,p2;
head=(student)malloc(sizeof(stu));
head->next=NULL;
p2=head;
p1=(student)malloc(sizeof(stu));
printf("请输入学号: ");
scanf("%ld",&p1->num);
while(p1->num!=0)
{
printf("请输入姓名: ");
scanf("%s",p1->name);
printf("请输入性别: ");
scanf("%s",&p1->sex);
p2->next=p1;
p2=p1;
p1=(student)malloc(sizeof(stu));
printf("请输入学号: ");
scanf("%ld",&p1->num);
}
p2->next=NULL;
}
void print(student head)
{
student q;
q = head->next;
if (q!= NULL)
while (q!=NULL)
{
printf("%ld\t%s\t%s\n",q->num,q->name,q->sex);
q=q->next;
}
else
printf("void list!\n");
}
int main()
{
student head=NULL;
ceate(head);
print(head);
system("PAUSE");
return 0;
}