【C语言程序设计第四版】例12-2代码

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
struct sysuser{
    char username[20];
    char password[8];
};
void encrypt_(char *pwd);
int main(void){
    
    FILE *fp;
    int i;
    
    struct sysuser su;
    if ((fp=fopen("f12-2.txt", "w")) == NULL) {
        printf("File open error!\n");
        exit(0);
    }
    for (i=1; i<=5; i++) {
        printf("Enter %d th sysuser(name passwod):", i);
        scanf("%s%s",su.username, su.password);
        encrypt_(su.password);
        fprintf(fp, "%s %s\n", su.username, su.password);
    }
    if (fclose(fp)) {
        printf("Can not close the file!\n");
        exit(0);
    }
    
    return 0;
}

void encrypt_(char *pwd){
    int i;
    
    for (i = 0; i < strlen(pwd); i++) {
        pwd[i] = pwd[i] ^ 15;
    }
}

 

posted @ 2021-09-27 11:21  就是想学习  阅读(48)  评论(0编辑  收藏  举报