| 网站首页 | 业界新闻 | 小组 | 交易 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
ADSL如何秒变专线,公网IP盒子了解一下千里之行 始于足下
共有 272 人关注过本帖
标题:为什么判断密码是否正确的时候变量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







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

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