为什么判断密码是否正确的时候变量i始终不为0?
为什么判断密码是否正确的时候变量i始终不为0?源代码:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main()
{
char name[256];
char username[128];
char mailaddress[256];
char psw[256];
char userpsw[256];
char userpsw1[256];
char address[128]="d:\\c\\test\\";
FILE*file;
file=fopen("d:\\c\\test\\user.txt","r+");
if(!file)
{
file=fopen("d:\\c\\test\\user.txt","w+");
fclose(file);
}
else
{
fclose(file);
}
int choose1;
printf("1 登录\n2 注册\n");
scanf("%d",&choose1);
if(choose1==2)
{
system("cls");
printf("请输入姓名\n");
scanf("%s",&username);
printf("请输入邮箱地址\n");
scanf("%s",&mailaddress);
printf("请输入密码\n");
scanf("%s",&userpsw);
printf("请确认密码\n");
scanf("%s",&userpsw1);
int ret1;
ret1=strcmp(userpsw,userpsw1);
if(ret1==0)
{
printf("注册成功!\n");
char address1[128]="d:\\c\\test\\user\\";
char txtname[8]="姓名:";
char txtmailaddress[32]=" 邮箱地址:";
strcat(address1,username);
strcat(address1,".txt");
strcat(txtname,username);
strcat(txtmailaddress,mailaddress);
FILE*file1;
file1=fopen(address1,"w+");
fputs(txtname,file1);
fputs(txtmailaddress,file1);
char address2[64]="d:\\c\\test\\user\\";
strcat(address2,username);
strcat(address2,"password");
strcat(address2,".txt");
FILE*file2;
file2=fopen(address2,"w");
fputs(userpsw1,file2);
}
else printf("两次密码不一致\n");
}
else if(choose1==1)
{
system("cls");
printf("请输入账号\n");
scanf("%s",&name);
printf("请输入密码\n");
scanf("%s",&psw);
char read[32];
char address[128]="d:\\c\\test\\user\\";
strcat(address,name);
strcat(address,".txt");
file=fopen(address,"r");
if(file==NULL)
{
printf("账号不存在\n");
}
else
{
char address[128]="d:\\c\\test\\";
strcat(address,name);
strcat(address,"password");
strcat(address,".txt");
file=fopen(address,"r");
char pswr[256];
fgets(pswr,256,file);
int i=strcmp(psw,pswr);
if(i==0)
{
printf("登录成功!\n");
}
else
{
printf("密码错误!\n");
}
}
}
}