zoukankan      html  css  js  c++  java
  • 第六次作业

    #include<stdio.h>
    #include<string.h>
    #include<math.h>
    #include<stdlib.h>
    struct sysuser
    {
     char username[20];
     char password[16];
    };
    int zhuce();
    int CheckUserValid(struct sysuser *psu);
    int main()
    {
     printf("请注册账号 ");
     if(zhuce)
     printf("注册成功 ");
     struct sysuser su;
     printf("输入用户名 ");
     scanf("%s",su.username);
     printf("输入密码 ");
     scanf("%s",su.password);
     if(CheckUserValid(&su)==1)
     printf("登陆成功 ");
     else
     printf("账号或密码不正确 ");
    }
    int zhuce()//注册函数
    {
     FILE *fp;
     struct sysuser su;//文件指针
     if((fp=fopen("user.txt","w"))==NULL)
     {
      printf("抱歉,没有指定文件");
         exit(0);
     }
     printf("请输入用户名 ");
     scanf("%s",su.username);
     printf("请输入密码 ");
     scanf("%s",su.password);
     fprintf(fp,"%s %s ",su.username,su.password);
     fclose(fp);
     return 1;
    }
    int CheckUserValid(struct sysuser *psu)//登录函数
    {
     FILE *fp;
     if((fp=fopen("user.txt","r"))==NULL)
     {
      printf("找不到指定文件");
      exit(0);
     }
     char use[32],rightUse[32],pass[16];
     int flag=0;
     strcpy(use,(*psu).username);
     strcpy(pass,(*psu).password);
     strcat(use," ");
     strcat(use,pass);
     strcat(use," ");
     while(!feof(fp))
     {
      fgets(rightUse,32,fp);
      if(strcmp(use,rightUse)==0)
      {
       flag=1;
       break;
      }
      if(fclose(fp))
      {
       printf("不能关闭这个文件");
       exit(0) ;
      }
     }
     return flag;
    }

  • 相关阅读:
    电商概念
    Linux知识点(二)
    linux知识点
    笔记8月20日
    考勤运行提示‘Length of values (115) does not match length of index (116) >>> ’
    数据透视表+数据条
    CCRC软件开发评审-材料应该怎么准备
    python os.walk函数
    httprunner 断言报错 expect_value 和check_value类型不一致
    自动化-Yaml文件读取函数封装
  • 原文地址:https://www.cnblogs.com/yvvq/p/10200998.html
Copyright © 2011-2022 走看看