c语言学生管理系统之用户输入

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;
}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值