首页 > 电脑

帮我看看我的c语言代码有什么问题?

更新时间2018-07-14 13:01:21

#include <stdio.h>

#include <time.h>

#include <string.h>

#include <windows.h>

int main()

{

    struct tm *time_now;

    time_t secs_now;

    long longtxt=900000;

    char str1[80],str2[80],pass_use[20],pass[20]={"hy_330682200705110016"};

    char use[50][200],config[250][250];

    FILE *fp1;

    FILE *fp2;

    fp1=fopen("read.txt","a+"); //打开文件,追加写

    fp2=fopen("log.txt","r+");//读取用户信息

    printf("请输入密码以查看你的各账户信息: ");

    scanf("%s",pass_use); 

    system("cls");

    time(&secs_now);

    time_now = localtime(&secs_now);

    if (strcmp(pass,pass_use)!=0)

    {

        printf("密码正确! ");

        strftime(str1, 80, "%Y.%m.%d %H:%M 读取成功!", time_now);

        fprintf(fp1,"%s ",str1);

        printf("以下是历史用户试读取的数据,最后一条是您的数据: ");

        fgets(use,longtxt,fp1);

        printf(" 请确保你的密码不会被看到! ");

        system("pause");

        system("cls");

        fgets(config,longtxt,fp2);

        fclose(fp1);

        fclose(fp2);

        system("pause");

    }

    else

    {     

        printf("你的密码有误!");

        strftime(str, 80, "%Y.%m.%d %H:%M 读取失败!", time_now);

        fprintf(fp1,"%s ",str);

        Sleep(2000);

        fclose(fp1);

        return 0;

    }

}


你的

      printf("以下是历史用户试读取的数据,最后一条是您的数据: ");

        fgets(use,longtxt,fp1);

不是读用户数据

fp1对应的是read.txt,是以a+方式打开的,它不能读的

函数参数也不对,longtxt的值不能超过use的下标的

最后你读到的fgets(config,longtxt,fp2);也不对

首先,config是二维数据,不能通过gets赋值的(它只能读到一维数组)

其次,你的config在程序中没有任何作用

程序从结构上,到函数的调用上都有问题的

建议,先画程序框图,设计程序结构,且检查每个参数的正确性

相关标签:c语言

上一篇:骁龙430机身32跟骁龙430机身64的,除了内存区别大还有其他区别的吗???

下一篇:有人了解济南电脑租赁公司吗?说下哪家做的好呢?