【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!
");
        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
", su.username, su.password);
    }
    if (fclose(fp)) {
        printf("Can not close the file!
");
        exit(0);
    }
    
    return 0;
}

void encrypt_(char *pwd){
    int i;
    
    for (i = 0; i < strlen(pwd); i++) {
        pwd[i] = pwd[i] ^ 15;
    }
}
原文地址:https://www.cnblogs.com/sidianok/p/15342158.html