标题:编写了一个登陆程序,有BUG,有大神能看看嘛?
取消只看楼主
caishou
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2019-12-21
 问题点数:0 回复次数:0 
编写了一个登陆程序,有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 ;
      }
搜索更多相关主题的帖子: password str 登陆 printf include 
2019-12-21 19:07



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




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

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