zoukankan      html  css  js  c++  java
  • 【C语言程序设计第四版】例12-4代码

    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    
    struct sysuser{
        char username[20];
        char password[8];
    };
    void encrypt_(char *pwd);
    int checkUserValid(struct sysuser *psu);
    
    int main(void){
        struct sysuser su;
        printf("Enter username: ");scanf("%s",su.username);
        printf("Enter password: ");scanf("%s",su.password);
        
        if (checkUserValid(&su)==1) {
            printf("Valid user!
    ");
        }else{
            printf("Invalid user!
    ");
        }
        
        return 0;
    }
    
    void encrypt_(char *pwd){
        int i;
        for (i = 0; i<strlen(pwd); i++) {
            pwd[i] = pwd[i]^15;
        }
    }
    
    int checkUserValid(struct sysuser *psu){
        FILE *fp;
        char usr[30], usr1[30], pwd[10];
        int check=0;
        
        strcpy(usr, psu->username);
        strcpy(pwd, psu->password);
        encrypt_(pwd);
        strcat(usr, " ");strcat(usr, pwd);strcat(usr, "
    ");
        
        if ((fp = fopen("f12-2.txt", "r"))==NULL) {
            printf("File open error!
    ");
            exit(0);
        }
        
        while (!feof(fp)) {
            fgets(usr1, 30, fp);    // 全文扫描,牛逼
            if (strcmp(usr, usr1) == 0) {
                check =1;break;
            }
        }
        
        if (fclose(fp)) {
            printf("Can not close the file!
    ");
            exit(0);
        }
        
        return check;
    }
  • 相关阅读:
    lua module
    lua require
    lua io
    lua table2
    lua table1
    【leetcode】魔术排列
    【leetcode】速算机器人
    【leetcode】黑白方格画
    【leetcode】根据数字二进制下 1 的数目排序
    【leetcode】插入区间
  • 原文地址:https://www.cnblogs.com/sidianok/p/15343079.html
Copyright © 2011-2022 走看看