第一轮输入数据没问题,但是第二轮就跳过前两个直接到第三个了,求高手帮忙
程序代码:#include<stdio.h>
#include<malloc.h>
#include <stdlib.h>
typedef struct student
{
int mum;
char name[20];
int age;
char sex[5];//w and M
// int birthday[2];
// char address[50];
// int photo;
// char Email[20];
struct student *next;
}st;
int n;
st *creat(void)
{
void scan(st *q);
st *head;
st *p1,*p2;
p1=p2=(st *)malloc(sizeof(st));
scan(p1);
head=NULL;
while((*p1).mum!=0)
{
n=n+1;
if(n==1)head=p1;
else p2->next=p1;
p2=p1;
p1=(st *)malloc(sizeof(st));
scan(p1);
}
p2->next=NULL;
return(head);
}
void scan(st *q)
{
printf("请输入学号");
scanf("%d",&(*q).mum);
printf("输入姓名");
scanf("%s",(*q).name);
printf("请输入年龄");
scanf("%d",&(*q).age);
printf("请输入性别");
scanf("%c",(*q).sex);
/* printf("请输入出生年月(年-月-日)");
scanf("%d-%d-%d",(*q).birthday[0],(*q).birthday[1],(*q).birthday[2]);
printf("请输入家庭住址");
scanf("%f",(*q).address);
printf("请输入电话号码");
scanf("%d",(*q).photo);
printf("请输入E-mail");
scanf("%f",(*q).Email); */
}
void print(st *m)
{
printf("mum name age sex ");
printf( "%4d %s %2d %s ",(*m).mum,(*m).name,(*m).age,(*m).sex);
}
void print1(st *head)
{
st *k;
k=head;
if(head!=NULL)
do
{
print(k);
k=k->next;
}while(k!=NULL);
}
void main()
{
st *head;
head=creat();
print1(head);
}
第一轮输入数据没问题,但是第二轮就跳过前两个直接到第三个了。。有人知道是怎么回事吗?帮忙指正一下谢谢[ 本帖最后由 mcf0419 于 2010-5-27 09:34 编辑 ]








