⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cuser.c

📁 商品管理系统 1)进货员对商品基本信息进行输入、删除、修改和查询 (2)销售员对商品的基本信息进行查询和统计 (3)并可以对库存信息进行查询和修改 (4)顾客购买商品
💻 C
字号:
#ifndef CREATUSER
 #define CREATUSER
 #include <stdio.h>
 #include "user.h"
 #define NUM 10
 /*创建用户信息*/
 void CreatUser()
 {
  FILE *fp=NULL;
  user Show;
  user TempS;
  char DataFile[40]="yonghu";/* 存储投票人信息的文件名 */
  int count=1;
  fp=fopen(DataFile,"ab");
  clrscr();
  /* 如果当前文件不存在,提示打开文件失败 */
  if(fp==NULL)
  {
   printf("\nOpen file %s fail!End with any key.\n",DataFile);
   perror("Open file fail");
   getch();
   exit(1);
  }
  /* 如果成功打开文件,则提示输入序号、用户名、密码、权限等相关信息 */
  printf("input number,name and password.number is 0 means input is end.\n");
  printf("Number is not exceed 10 figures,Name is not exceed 20 characters,range of grade:0~1");
  /* 循环从键盘上读取投票人输入的投票人相关信息 */
  while(1)
  {
    printf("\ninput 'number=0' means end input.\n");
    printf("number:");
    scanf("%ld",&TempS.Number);
    if(TempS.Number==0)
    {
     break;
    }
    printf("name:");
    scanf("%s",TempS.Name);
    TempS.Name[19]='\0';

    printf("password:");
    scanf("%s",TempS.ps);
    TempS.ps[7]='\0';
    printf("power=");
    scanf("%d",&TempS.power);

    if(TempS.power!=1)
    {
     TempS.power=0;
    }
    /* 如遇无法写入文件的异常,则加以提示 */
    if(fwrite(&TempS,sizeof(user),1,fp)!=1)
    {
     printf("\nwrite file %s fail! End with any key\n",DataFile);
     perror("Write file fail");
     getch();
     exit(1);
    }
    count++;
  }
  /* 如果输入的数据量超过最大允许的范围,则提示数据不能录入 */
  fclose(fp);
  /* 在屏幕上显示文件内容 */
  printf("The data you input is store successful %s in file.\n",DataFile);
  printf("Content as follow:\n");
  fp=fopen(DataFile,"rb");
  if(fp==NULL)
  {
   printf("\nOpen file %s fail! End With any key \n",DataFile);
   perror("Open file fail");
   getch();
   exit(1);
  }
  printf("\nNumber\t\tName\t\tpassword\t\tpower\n");
  while(fread(&Show,sizeof(user),1,fp)!=(int)NULL)
  {
   printf("\n%ld\t\t%s\t\t%-8s\t\t%d\n",Show.Number,Show.Name,Show.ps,Show.power);
  }
  fclose(fp);
  printf("press any key to continu...");
  getch();
}
#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -