标题:为什么判断密码是否正确的时候变量i始终不为0?
只看楼主
喵小漾
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2019-2-6
 问题点数:0 回复次数:0 
为什么判断密码是否正确的时候变量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");
            }
        }
    }
}
搜索更多相关主题的帖子: char address FILE printf strcat 
2019-02-06 16:12



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-492973-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.254236 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved