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;
    }
  • 相关阅读:
    python3.7安装pygame
    Jmeter定时器
    弱网测试
    面试心得123
    如何保证测试项目的质量
    LeetCode448-数组中消失的数字
    LeetCode-两数相加
    JVM-Class文件的结构
    leetcode-222完全二叉树的节点个数
    Java虚拟机常用的性能监控工具
  • 原文地址:https://www.cnblogs.com/sidianok/p/15343079.html
Copyright © 2011-2022 走看看