编写了一个登陆程序,有BUG,有大神能看看嘛?
想编写一个登陆程序,把登陆密码以文本文档的形式储存在电脑,可运行程序后,打开文件调用后生成的文档不为空,导致无法检测有无密码。请问怎么哪里有问题?
程序代码:
#include <stdio.h> #include <windows.h> #include <string.h> #include "ENPASS_H.h" #define SIZE 10 void password_login(){ /*密码函数*/ char pwd[5]; int i = 3; int n = 4; char str[5]; int x =0; char *pp = NULL; FILE *fp; if((fp = fopen("D:\\1.txt","a+")) == NULL) { printf("sorry,can't open the password file."); exit(1); } fgets(str,5,fp); if(str[0] == '\0') { printf("000"); printf("please input new password:\n"); scanf("%s",str); fputs(str,fp); fclose(fp); printf("OK!\n"); system("cls"); Sleep(1200); } a: for(x=0;x<SIZE;x++) { printf("%d\n",str[x]); } printf("please input password:\n"); scanf("%s",pwd); if(!strcmp(str,pwd)){ printf("This password is true."); Sleep(1000); system("cls"); }else{ Sleep(500); system("cls"); --i; printf("False,You just have %d times to input password.\n",i); if(i == 0) { printf("Sorry,you have no times to input.\n"); printf("Program will exit."); Sleep(500); exit(0); } else{ goto a; } } return ; }