后生成的文档不为空,导致无法检测有无密码。请问怎么哪里有问题?
只有本站会员才能查看附件,请 登录

#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 ;
}
#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 ;
}