zoukankan      html  css  js  c++  java
  • 随笔--C语言学习

    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include <stdbool.h>

    typedef struct
    {
    char username[20];
    char sex[10];
    long int usernum;
    int password;
    }stu;

    stu stud[20];

    void initUser();
    void loginByUserNum();
    bool loginByPassword(int index);
    void searchByName();


    void initUser()
    {
    FILE *fp;
    int i;
    char a[20];
    fp = fopen("学生信息.txt","r");
    fscanf(fp,"%s %s %s %s",a,a,a,a);
    for(i = 0; i < 10; i++)
    {
    fscanf(fp,"%s %s %ld %d",stud[i].username,stud[i].sex,&stud[i].usernum,&stud[i].password);
    }
    for(i = 0; i < 10; i++)
    {
    printf("%s %s %ld %d ",stud[i].username,stud[i].sex,stud[i].usernum,stud[i].password);
    }
    }
    bool loginByPassword(int index)
    {
    int password;
    printf(" 请输入密码:");
    scanf("%d",&password);
    if(stud[index].password == password){
    return true;
    }
    else{
    printf(" 密码错误,请重新输入 ");
    loginByPassword(index);
    }
    }
    void loginByUserNum()
    {
    long int userNum;
    int i;

    printf(" 请输入学号:");
    scanf("%ld",&userNum);
    printf(" 你输入的是%ld ",userNum);
    for(i = 0; i < 10; i++)
    {
    if(stud[i].usernum == userNum)
    {
    if(loginByPassword(i))
    {
    printf(" ********成功登陆图书馆预约系统********");
    return;
    }
    }
    else
    {
    printf(" 学号不存在 ");
    loginByUserNum();
    }
    }
    }

    void searchByName()
    {
    printf(" ********请输入登陆信息********");
    loginByUserNum();
    }

    int main()
    {
    initUser();
    searchByName();
    return 0;
    }

  • 相关阅读:
    Socket
    字符串,byte,字典转换整理
    1-嵌入式面试题库
    10-FreeRTOS 队列
    9-FreeRTOS API获取任务使用CPU时间
    7-代码区 | 常量区 | 静态区(全局区) | 堆区 | 栈区
    8-FreeRTOS任务API
    7-FreeRTOS时间片进行任务调度
    6-C指针
    用Union体测试处理器大小端
  • 原文地址:https://www.cnblogs.com/icelan/p/6201557.html
Copyright © 2011-2022 走看看