大佬们,帮我看看这个程序哪错了,一到要输入数据的时候就不行了
#include<stdio.h>
#include<stdlib.h>
#include<malloc.h>
#include<string.h>
struct student
{
char num[10];
char name[10];
char clas[10];
char adress[10];
char phonenum[10];
char email[10];
struct student *next;
};
struct student *creat()
{int n;
struct student *head;
struct student *p1,*p2;
n=0;
p1=p2=(struct student *)malloc(sizeof(struct student));
printf("请输入您要录入的学生通讯信息:\n");
printf("\t学号\t姓名\t班级\t地址\t电话\tE-mail\n");
scanf("%s %s %s %s %s %s",p1->num,p1->name,p1->clas,p1->adress,p1->phonenum,p1->email);
head=NULL;
while (strcmp(p1->num,0)!=0);
{
n=n+1;
if(n==1)head=p1;
else p2->next=p1;
p2=p1;
p1=(struct student *)malloc(sizeof(struct student));
scanf("%s %s %s %s %s %s",p1->num,p1->name,p1->clas,p1->adress,p1->phonenum,p1->email);
}
p2->next=NULL;
return (head);
}
int main()
{
FILE*fp;
struct student *head;
head=creat();
if((fp=fopen("stu.dat","wb"))==NULL)
{
printf("打开文件错误,按任意键退出...\n");
return 0 ;
}
while(1)
{
if(fwrite(head,sizeof(struct student),1,fp)!=1)
printf("写文件错误!!\n");
}
fclose(fp);
printf("保存完毕\n");
return 0;
}