LINK Input(LINK head) //用户输入批量输入学生信息,注意,会覆盖以前的信息
{
LINK p = (LINK)malloc(sizeof(NODE));
LINK h = (LINK)malloc(sizeof(NODE));
p = head->next;
while(p)
{
h = p;
p = p->next;
}
LINK tail ;
tail = h;
long x ;
long y ;
int flag = 0;
while(1)
{
flag = 0;
LINK q = (LINK)malloc(sizeof(NODE));
q = head->next ;
int r = 1;
printf("---------请输入学生学号,以-1结束\n");
r = scanf("%ld",&x);
for(; q!=NULL; q=q->next)
{
y = q->number ;
if(x == y)
{
flag = 1;
break;
}
}
if(x == -1)
{
break;
}
else if ( r == 0) //保护程序,免受用户破坏
{
printf("---------学号格式输入错误,请重新输入\n");
fflush(stdin);
continue;
}
else if (flag) //判断程序是否出错
{
printf("学号重复,请重新输入\n");
continue;
}
LINK p = (LINK)malloc(sizeof(NODE));
p->number = x;
printf("--------请输入学生姓名\n");
scanf("%s",p->name);
printf("--------请输入学生性别\n");
scanf("%s",p->sex);
while(1) //判断生日是否出错
{
printf("--------请输入学生出生年月日,中间以点隔开\n");
scanf("%d.%d.%d",&p->year,&p->month,&p->day);
if(p->month<1 || p->month > 12)
{
printf("输入月份出错,请重新输入\n");
continue;
}
else if( ( p->month >=1 && p->month<=7 && p->month % 2 == 1 && p->day > 31) || p->day < 1 )
{
printf("输入日期出错,请重新输入\n");
continue;
}
else if (( p->month >=1 && p->month<=7 && p->month % 2 == 0 && p->day > 30) || p->day < 1)
{
printf("输入日期出错,请重新输入\n");
continue;
}
else if ( ( p->month >=8 && p->month<=12 && p->month % 2 == 0 && p->day > 31) || p->day < 1)
{
printf("输入日期出错,请重新输入\n");
continue;
}
else if(( p->month >=8 && p->month<=12 && p->month % 2 == 1 && p->day > 30) || p->day < 1)
{
printf("输入日期出错,请重新输入\n");
continue;
}
else if ((p->month == 2 && p->year %4 == 0 && p->day > 29) || p->day <1)
{
printf("输入日期出错,请重新输入\n");
continue;
}
else if ((p->month == 2 && p->year %4 != 0 && p->day > 28) || p->day <1)
{
printf("输入日期出错,请重新输入\n");
continue;
}
break;
}
printf("--------请按顺序输入学生数学、语文、英语三科成绩\n");
scanf("%f%f%f",&p->score[0],&p->score[1],&p->score[2]);
fflush(stdin);
tail->next = p;
tail = p;
tail->next = NULL ;
}
tail->next = NULL ;
return head;
}
c语言学生管理系统之用户输入
最新推荐文章于 2023-02-28 10:08:48 发布