mima5.txt
来自「密码程序是一个图形c编的隐形的」· 文本 代码 · 共 64 行
TXT
64 行
#include <stdio.h>
#include <malloc.h>
#include <stdlib.h>
#include <string.h>
main(){
FILE *fp;
int iCount = 0;
char *cPassWord = NULL,*cTempData = NULL,ch = 0;
cPassWord = (char *)malloc(100);
cTempData = (char *)malloc(100);
if ((fp = fopen("password.bat","r")) == NULL){
/*原来没有密码时,初始化密码,保存到文件中*/
printf("Please init password!\n");
fp = fopen("password.bat","w+");
while ((*(cPassWord + iCount) = getch()) != '\r'){
printf("*");
iCount++;
}
*(cPassWord + iCount) = 0;
printf("\n");
fprintf(fp,"%s",cPassWord);
fclose(fp);
exit(0);
}
fscanf(fp,"%s",cPassWord);
iCount = 0;
/*输入密码*/
printf("Please input the password:\n");
while ((*(cTempData + iCount) = getch()) != '\r'){
printf("*");
iCount++;
}
*(cTempData + iCount) = 0;
printf("\n");
while (1){
if (strcmp(cPassWord,cTempData) == 0){/*如果密码正确,退出循环*/
printf("Welcome to XXXXXXX");
break;
}
/*否则重新输入*/
system("cls");
printf("Password is wrong!\nPlease input the password again:\n");
while ((*(cTempData + iCount) = getch()) != '\r'){
printf("*");
iCount++;
}
*(cTempData + iCount) = 0;
printf("\n");
}
printf("Do you modify the password?(1,YES;2,NO)\n");
if((ch = getchar()) == '1'){/*修改密码*/
fclose(fp);
fp = fopen("password.bat","w+");
fflush(stdin);
gets(cPassWord);
fprintf(fp,"%s",cPassWord);
}
fclose(fp);
free(cPassWord);
cPassWord = NULL;
free(cTempData);
cTempData = NULL;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?