模仿TXT文本输入程序

// TXT.cpp : Defines the entry point for the console application.
//
/*
================================================
Name  : TXT.cpp
Author     : 金开龙
Copyright   : 乐成数字通信学院
Description : 模仿Windows的记事本,自己设计并实现一个和其类似
              的一个文本输入界面,要求有用户登陆系统和文件存取系统
==================================================
 */
#include "stdafx.h"
#include "stdio.h"
#include "conio.h"
#include "string.h"
#include "stdlib.h"
#include <windows.h>
#include <time.h>

int nN=0;

// -------------------------------------------
// 函数名  :鼠标定位函数
// 函数作用:实现鼠标在控制台输出界面的输出
// ----------------------------------------------
//
void  gotoxy(int x,int y) 
{  
 COORD c;  
 c.X = x - 1;  
 c.Y = y - 1;  
 SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),c);  

struct stMessage
{
 char szUserLoadName[20];
 char szUserLoadPassword[20];
};//定义一个用来存储用户名和密码的结构体数组

// -------------------------------------------
// 函数名  :隐藏鼠标函数
// 函数作用:隐藏鼠标的闪烁
// ----------------------------------------------
//
void HideCursor()
{
 CONSOLE_CURSOR_INFO     cci;
 cci.dwSize   =   1;   //这个设置光标的大小,值为1-100
 cci.bVisible   =   FALSE;   //这个设置光标是否显示
 
 
 HANDLE   hOutputHandle   =   GetStdHandle(   STD_OUTPUT_HANDLE   );
 BOOL   bResult   =   SetConsoleCursorInfo(hOutputHandle,   &cci);   //设置光标信息
}

// -------------------------------------------
// 函数名  :显示鼠标函数
// 函数作用:显示鼠标的闪烁
// ----------------------------------------------
//
void ShowCursor()
{
 CONSOLE_CURSOR_INFO     cci;
 cci.dwSize   =   1;   //这个设置光标的大小,值为1-100
 cci.bVisible   =   TRUE;   //这个设置光标是否显示
 
 
 HANDLE   hOutputHandle   =   GetStdHandle(   STD_OUTPUT_HANDLE   );
 BOOL   bResult   =   SetConsoleCursorInfo(hOutputHandle,   &cci);   //设置光标信息
}

// -------------------------------------------
// 函数名  :显示界面函数
// 函数作用:显示登陆之后显示的界面
// ----------------------------------------------
//
void ShowmainFace()
{
 system("title 请按照提示进行输入提示后面的英文代码(不区分大小写)");
 printf("┌──────────────────────────────────┐/n");
 printf("│               欢迎您的回来,请按照提示进行相应操作                 │/n");
 printf("├────────┬────────┬────────┬───────┤/n");
 printf("│    文件(F)     │     用户(U)    │    查看(S)     │    帮助(H)   │/n");
 printf("├────────┴────────┴────────┴───────┤/n");
 printf("│                                                                    │/n");
 printf("│                                                                    │/n");
 printf("│                                                                    │/n");
 printf("│                                                                    │/n");
 printf("│                                                                    │/n");
 printf("│                                                                    │/n");
 printf("│                                                                    │/n");
 printf("│                                                                    │/n");
 printf("│                                                                    │/n");
 printf("│                                                                    │/n");
 printf("│                                                                    │/n");
 printf("│                                                                    │/n");
 printf("│                                                                    │/n");
 printf("│                                                                    │/n");
 printf("│                                                                    │/n");
 printf("├────────────────┬─────────────────┤/n");
 printf("│                                │                                  │/n");
 printf("└────────────────┴─────────────────┘/n");

}


// -------------------------------------------
// 函数名  :显示界面函数
// 函数作用:显示在登陆之,在欢迎界面之后的显示界面
// ----------------------------------------------
//
void ShowmainFaceFrist()
{

 system("title 欢迎使用 请输入U进行用户登陆,输入H查看帮助信息!");
 printf("┌──────────────────────────────────┐/n");
 printf("│   欢迎使用本文本输入系统,请先登陆,没有帐号请先注册。谢谢使用     │/n");
 printf("├────────────────┬─────────────────┤/n");
 printf("│            用户(U)             │             帮助(H)              │/n");
 printf("├────────────────┴─────────────────┤/n");
 printf("│                                                                    │/n");
 printf("│                                                                    │/n");
 printf("│                                                                    │/n");
 printf("│                                                                    │/n");
 printf("│                                                                    │/n");
 printf("│                                                                    │/n");
 printf("│                                                                    │/n");
 printf("│                                                                    │/n");
 printf("│                                                                    │/n");
 printf("│                                                                    │/n");
 printf("│                                                                    │/n");
 printf("│                                                                    │/n");
 printf("│                                                                    │/n");
 printf("│                                                                    │/n");
 printf("│                                                                    │/n");
 printf("├────────────────┬─────────────────┤/n");
 printf("│                                │                                  │/n");
 printf("└────────────────┴─────────────────┘/n");
 
}


// -------------------------------------------
// 函数名  :时间函数
// 函数作用:从PC中得到一个静态时间来进行输出
// ----------------------------------------------
//
void Time()
{
 time_t t;
 
 time(&t);
 printf("%s/n", ctime(&t));
}

void UserRegisterFace()
{
 printf("┌──────────────────────────────────┐/n");
 printf("│                     欢迎您进入账户注册界面                         │/n");
 printf("│           友情提示用户名和密码长度不能大于20(区分大小写)           │/n");
    printf("├──────────────────────────────────┤/n");
 printf("│                                                                    │/n");
 printf("│                                                                    │/n");
 printf("│                                                                    │/n");
 printf("│                                                                    │/n");
 printf("│                                                                    │/n");
 printf("│                                                                    │/n");
 printf("│                                                                    │/n");
 printf("│                                                                    │/n");
 printf("│                                                                    │/n");
 printf("│                                                                    │/n");
 printf("│                                                                    │/n");
 printf("│                                                                    │/n");
 printf("│                                                                    │/n");
 printf("│                                                                    │/n");
 printf("│                                                                    │/n");
 printf("│                                                                    │/n");
 printf("├────────────────┬─────────────────┤/n");
 printf("│                                │                                  │/n");
 printf("└────────────────┴─────────────────┘/n");

}

// -------------------------------------------
// 函数名  :显示界面函数
// 函数作用:在选择登陆之后,用来显示用户登陆输入的界面
// ----------------------------------------------
//
void UserLoadFace()
{
 printf("┌──────────────────────────────────┐/n");
 printf("│                        欢迎您进入登陆界面                          │/n");
 printf("│           友情提示:请输入注册时的账户和密码(区分大小写)           │/n");
    printf("├──────────────────────────────────┤/n");
 printf("│                                                                    │/n");
 printf("│                                                                    │/n");
 printf("│                                                                    │/n");
 printf("│                                                                    │/n");
 printf("│                                                                    │/n");
 printf("│                                                                    │/n");
 printf("│                                                                    │/n");
 printf("│                                                                    │/n");
 printf("│                                                                    │/n");
 printf("│                                                                    │/n");
 printf("│                                                                    │/n");
 printf("│                                                                    │/n");
 printf("│                                                                    │/n");
 printf("│                                                                    │/n");
 printf("│                                                                    │/n");
 printf("│                                                                    │/n");
 printf("├────────────────┬─────────────────┤/n");
 printf("│                                │                                  │/n");
 printf("└────────────────┴─────────────────┘/n");
 
}

// -------------------------------------------
// 函数名  :显示界面函数
// 函数作用:显示"文件"的菜单项
// ----------------------------------------------
//
void ShowFileMenu()
{
 gotoxy(1,5);
 printf("┌────┐/n");
 gotoxy(1,6);
    printf("│新建(N) │/n");
 gotoxy(1,7);
    printf("├────┤/n");
 gotoxy(1,8);
    printf("│打开(O) │/n");
 gotoxy(1,9);
    printf("├────┤/n");
 gotoxy(1,10);
    printf("│保存(S) │/n");
 gotoxy(1,11);
    printf("├────┤/n");
 gotoxy(1,12);
    printf("│退出(X) │/n");
 gotoxy(1,13);
    printf("└────┘/n");
 gotoxy(1,14);
 
}

// -------------------------------------------
// 函数名  :显示界面函数
// 函数作用:显示"用户"的菜单项
// ----------------------------------------------
//
void ShowUserMenu1()
{
 gotoxy(13,5);
 printf("┌────┐/n");
 gotoxy(13,6);
    printf("│注册(Z) │/n");
 gotoxy(13,7);
    printf("├────┤/n");
 gotoxy(13,8);
    printf("│登陆(L) │/n");
 gotoxy(13,9);
    printf("├────┤/n");
 gotoxy(13,10);
    printf("│查看(C) │/n");
 gotoxy(13,11);
    printf("├────┤/n");
 gotoxy(13,12);
    printf("│离开(X) │/n");
 gotoxy(13,13);
    printf("└────┘/n");
 gotoxy(13,14);

}

// -------------------------------------------
// 函数名  :显示界面函数
// 函数作用:显示"用户"的菜单项,并在此函数中实现用的注册、登陆、查看和退出操作
// ----------------------------------------------
//
void ShowUserMenu()
{
    char k;
 system("title 请按照提示进行输入提示后面的英文代码(不区分大小写)");

 gotoxy(13,5);
 printf("┌────┐/n");
 gotoxy(13,6);
    printf("│注册(Z) │/n");
 gotoxy(13,7);
    printf("├────┤/n");
 gotoxy(13,8);
    printf("│登陆(L) │/n");
 gotoxy(13,9);
    printf("├────┤/n");
 gotoxy(13,10);
    printf("│查看(C) │/n");
 gotoxy(13,11);
    printf("├────┤/n");
 gotoxy(13,12);
    printf("│离开(X) │/n");
 gotoxy(13,13);
    printf("└────┘/n");
 gotoxy(13,14);
 
    void UserRegister();
 void UserLoad();
    void ShowmainFaceFrist();
 void ShowUserMenu1();

 fflush(stdin);
 gotoxy(2,24);
 scanf("%c",&k);

    system("cls");
 ShowmainFaceFrist();
 ShowUserMenu1();
  

 switch (k)
 {
 case 'Z':
 case 'z':
   system("cls");
   ShowmainFace();
   gotoxy(3,22);
   Time();
   gotoxy(3,6);
   UserRegister();
   break; 
 case 'l':
 case 'L':
   system("cls");
   UserLoad();
  break;
 case 'c':
 case 'C':
     void View();
  View();
  Sleep(5000);
  system("cls");
  ShowmainFaceFrist();
  ShowUserMenu1();
  ShowUserMenu();
  break;
 case 'x':
 case 'X':
  printf("谢谢您你的使用,程序将退出/n");
  break;
 default:
  printf("您的输入有误,请重新输入/n");
  Sleep(1000);
  system("cls");
  ShowmainFaceFrist();
  ShowUserMenu1();
  ShowUserMenu();
         
 }

}

// -------------------------------------------
// 函数名  :显示界面函数
// 函数作用:显示"帮助"的菜单项
// ----------------------------------------------
//
void HelpFace()
{
 system("title 欢迎您进入帮助界面");
 system("cls");
 printf("┌──────────────────────────────────┐/n");
 printf("│                        欢迎您进入帮助界面                          │/n");
 printf("│                                                                    │/n");
    printf("├──────────────────────────────────┤/n");
 printf("│  1:请按照想对应操作后面括号内的字母进行输入来完成操作。           │/n");
 printf("│  2:帐号和密码输入要注意长度不能大于20而要区分大小写。             │/n");
 printf("│  3:用户经过系统数据库的身份验证后才能进入系统进行文字的输入。     │/n");
 printf("│  4:您要是新用户,您可以选择“用户” ->“注册”来进行新用户的注册  │/n");
 printf("│      以便你能完成文字的录入工作。                                  │/n");
 printf("│  5:请您在完成自己的文件录入后退出您的登陆,来保护您的文字信息的   │/n");
 printf("│      完整性和帐号的安全性。                                        │/n");
 printf("│                                                                    │/n");
 printf("│                                                                    │/n");
 printf("│                                                                    │/n");
 printf("│                                                                    │/n");
 printf("│                                                                    │/n");
 printf("│                                                                    │/n");
 printf("│                                                                    │/n");
 printf("│                                                                    │/n");
 printf("│                                                                    │/n");
 printf("├────────────────┬─────────────────┤/n");
 printf("│                                │                                  │/n");
 printf("└────────────────┴─────────────────┘/n");
}

// -------------------------------------------
// 函数名  :显示界面函数
// 函数作用:显示在文本录入时的界面框
// ----------------------------------------------
//
void FileInputFace()
{
 printf("┌──────────────────────────────────┐/n");
 printf("│                                                                    │/n");
 printf("│                                                                    │/n");
    printf("├──────────────────────────────────┤/n");
 printf("│                                                                    │/n");
 printf("│                                                                    │/n");
 printf("│                                                                    │/n");
 printf("│                                                                    │/n");
 printf("│                                                                    │/n");
 printf("│                                                                    │/n");
 printf("│                                                                    │/n");
 printf("│                                                                    │/n");
 printf("│                                                                    │/n");
 printf("│                                                                    │/n");
 printf("│                                                                    │/n");
 printf("│                                                                    │/n");
 printf("│                                                                    │/n");
 printf("│                                                                    │/n");
 printf("│                                                                    │/n");
 printf("│                                                                    │/n");
 printf("├────────────────┬─────────────────┤/n");
 printf("│                                │                                  │/n");
 printf("└────────────────┴─────────────────┘/n");
}

// -------------------------------------------
// 函数名  :查看用户名函数
// 函数作用:显示曾经注册过的所有用户名,并在界面停留5s以便观看
// ----------------------------------------------
//
void View()
{
 int nN1;
 FILE *pstream,*pNum;
 stMessage arr_stUserUserLoad[100];
 if((pNum=fopen("num.txt","rt"))!=NULL)
 {
  fscanf(pNum,"%d",&nN1);
  fclose(pNum);
 }
 
 if( (pstream=fopen("USER.txt","r+t"))!= NULL )
 {
  fread(arr_stUserUserLoad,sizeof(stMessage),nN1,pstream);
  gotoxy(3,15);
  printf("输出所有的注册用户名字(程序将要暂停5s,请及时观看)/n");
  gotoxy(3,16);
  for (int i=0;i<nN1;i++)
  {
   printf("%s  ",arr_stUserUserLoad[i].szUserLoadName);
  }
  fclose(pstream);
 }    
}

// -------------------------------------------
// 函数名  :显示用户输入内容的函数
// 函数作用:通过输入的用户名来输出所输入用户名曾经输入的所有内容
// ----------------------------------------------
//
void ShowUserContent()
{
 int nN1,i=0,nFileInputNum2;
 int flag=0;
 FILE *pstream,*pNum,*pUser,*pFileInputNum;
 stMessage arr_stUserUserLoad[100];
 char szSeek[20],szMID2[20];

 if((pNum=fopen("num.txt","rt"))!=NULL)
 {
  fscanf(pNum,"%d",&nN1);
  fclose(pNum);
 }
 
 gotoxy(4,24);
 printf("请输入你想查询的用户的名字                           /n");
 scanf("%s",szSeek);
 strcpy(szMID2,szSeek);
 if((pFileInputNum=fopen(strcat(szSeek,"Input.txt"),"rt")) != NULL )
 {
        
  fscanf(pFileInputNum,"%d",&nFileInputNum2);
  fclose(pFileInputNum);
        
 }
 else
  printf( "Problem opening the file/n" );

 if( (pstream=fopen("USER.txt","rt"))!= NULL )
 {  
  fread(arr_stUserUserLoad,sizeof(stMessage),nN1,pstream);
  fclose(pstream);
 }
 else
  printf( "Problem opening the file/n" );

    for (i=0;i<nN1;i++)
 {
  
  if (strcmp(szMID2,arr_stUserUserLoad[i].szUserLoadName)==0)
  {
   gotoxy(15,15);        
   if((pUser=fopen(strcat(szMID2,".txt"),"rt"))!= NULL)
   {
    char szfile[1000];
    memset(szfile,0,1000);
    fgets(szfile,nFileInputNum2+1,pUser);           
    printf("输出用户所写的信息/n");
    printf("%s/n", szfile); 
    fclose(pUser); 
   }  
   else
    printf("你所查找的用户信息无法返回信息/n"); 
  }

 }
}

// -------------------------------------------
// 函数名  :用户注册函数
// 函数作用:用来注册用户的函数,把用户注册的信息存到指定的文本中
// ----------------------------------------------
//
void UserRegister()
{
 system("title 请输入您想注册的账户和密码(密码和帐号都区分大小写且长度不要大于20)");

 FILE *stream,*pNum;
 int i,nI=1,nNum=0,x=0;
 stMessage arr_stUser[100];
 char szMidInPut[20];

 memset(szMidInPut,0,20);
 
 if((pNum=fopen("num.txt","rt"))!=NULL)
 {
  
  fscanf(pNum,"%d",&nN);
  fclose(pNum);
 }
 else
  printf( "Problem opening the file/n" );

 if( (stream=fopen("USER.txt","a+t")) != NULL)
 {
   for (i=0;i<100&&nI!=2;i++)
    {
      system("cls");
         UserRegisterFace();
         gotoxy(3,22);
         Time();

    void FrameShow(int x, int y, int width, int height) ;
    memset(&arr_stUser[i].szUserLoadName,0,20);
    memset(&arr_stUser[i].szUserLoadPassword,0,20);

    FrameShow(23,5,20,3);
    gotoxy(4,6);
       printf("请输入您的用户名  :");
    gotoxy(25,6);
       scanf("%s",arr_stUser[i].szUserLoadName);

    FrameShow(23,8,20,3);
    gotoxy(4,9);
       printf("请输入您的用户密码:");
    int ni=0;
    while(1)
    {

     int nj=ni++;
     szMidInPut[nj]=getch();
     if (szMidInPut[nj]==13)
      break;
     else
     {
      gotoxy(25+nj,9);
         putchar('*');
     }
    }
    for (x=0;x<ni-1;x++)
    {
     arr_stUser[i].szUserLoadPassword[x]=szMidInPut[x];
    }
    arr_stUser[i].szUserLoadPassword[x]='/0';
   
       /*scanf("%s",arr_stUser[i].szUserLoadPassword);*/
    putchar('/n');        
   
          nN+=1;
    nNum+=1;
    fwrite(&arr_stUser[i],sizeof(stMessage),1,stream);
    gotoxy(4,14);
       printf("     是否要继续进行注册处理,是请按1,不是请按2/n");
    gotoxy(4,15);
          scanf("%d",&nI);
 
 
     if (nI==2)
  {
   gotoxy(4,15);
   printf("谢谢您的使用理...../n");
   break;
  }
    }

/*    fwrite(arr_stUser,sizeof(stMessage),nNum,stream);*/
       fclose(stream);

    if((pNum=fopen("num.txt","wt"))!=NULL)
    {
     fprintf(pNum,"%d/n",nN);
     fclose(pNum);
    }
    else
  printf( "Problem opening the file/n" );

       gotoxy(4,16);
    printf("已有%d个注册了此程序",nN);
    }
 else
  printf( "Problem opening the file/n" );
 
}

// -------------------------------------------
// 函数名  :用户登陆函数
// 函数作用:用户在登陆成功之后可以进行的相关的TXT文本操作
// ----------------------------------------------
//
void UserLoad()
{
 system("title 请输入注册时的账户和密码(区分大小写)");

 int nN1,x,i=0,nFileInputNum2;
 int flag=0;
 FILE *pstream,*pNum,*pUser,*pFileInputNum;
 stMessage arr_stUserUserLoad[100],stFileInput;
 char szSeek[20],szMID1[20];
 char szMidInPut[20];

 if((pNum=fopen("num.txt","rt"))!=NULL)
 {
  fscanf(pNum,"%d",&nN1);
  fclose(pNum);
 }

 if( (pstream=fopen("USER.txt","r+t"))!= NULL )
 {
  system("cls");
  UserLoadFace();
  gotoxy(3,22);
  Time();

  fread(arr_stUserUserLoad,sizeof(stMessage),nN1,pstream);

        void FrameShow(int x, int y, int width, int height);
  getchar();
  FrameShow(24,5,20,3);
  gotoxy(4,6);
  printf("请输入注册时的用户名");
  gotoxy(26,6);
  gets(stFileInput.szUserLoadName);

  FrameShow(24,8,20,3);
  gotoxy(4,9); 
  printf("请输入注册时的密码  ");

  int ni=0;
  while(1)
  {
   
   int nj=ni++;
   szMidInPut[nj]=getch();
   if (szMidInPut[nj]==13)
    break;
   else
   {
    gotoxy(26+nj,9);
    putchar('*');
   }
  }
  for (x=0;x<ni-1;x++)
  {
   stFileInput.szUserLoadPassword[x]=szMidInPut[x];
  }
    stFileInput.szUserLoadPassword[x]='/0';
  putchar('/n');

     strcpy(szMID1,stFileInput.szUserLoadName);
   for (i=0;i<nN1;i++)
   {
    if ((strcmp(stFileInput.szUserLoadName,arr_stUserUserLoad[i].szUserLoadName)==0)&&(strcmp(stFileInput.szUserLoadPassword,arr_stUserUserLoad[i].szUserLoadPassword)==0))
    {
    int k;
    printf("/n  〓程序加载中>>>> ");
    for (k=1;k<=25;k++)
    {
     printf("★");
     Sleep(100);
    }

         system("cls");
        ShowmainFace();
     gotoxy(4,22);
     Time();
     gotoxy(40,22);
     printf("当前用户是:%s",stFileInput.szUserLoadName);
     gotoxy(19,2);
     Sleep(1000);
     printf("        欢迎%s使用文字录入界面     ",stFileInput.szUserLoadName);
     gotoxy(4,24);               
     printf("请输入你要进行的操作代码...");
     char cA,cB;
     scanf("%c",&cA);
     switch (cA)
     {
     case 'f':
     case 'F':
      ShowFileMenu();
      gotoxy(4,24);
      printf("请输入你现在需要进行的录入文件操作..");
      fflush(stdin);
      scanf("%c",&cB);
      
      switch (cB)
      {
      case 'n':
      case 'N':
       void FileInput(char szRecName[20]);      
       FileInput(stFileInput.szUserLoadName);
       break;
      case 'x':
      case 'X':
       gotoxy(13,16);
       printf("谢谢您你的使用,程序将退出/n");
       break;
      case 's':
      case 'S':
       break;
      case 'O':
      case 'o':
       if((pFileInputNum=fopen(strcat(szMID1,"Input.txt"),"rt")) != NULL )
       {
        
        fscanf(pFileInputNum,"%d",&nFileInputNum2);
        fclose(pFileInputNum);
        
       }
       else
        printf( "Problem opening the file/n" );
       
       gotoxy(4,24);
       printf("请输入你想查询的用户的名字                             /n");
       scanf("%s",szSeek);
       for (i=0;i<nN1;i++)
       {
        if (strcmp(szSeek,arr_stUserUserLoad[i].szUserLoadName)==0)
        {
         gotoxy(15,15);        
         if((pUser=fopen(strcat(szSeek,".txt"),"rt"))!= NULL)
         {
          char szfile[1000];
          memset(szfile,0,1000);
          fgets(szfile,nFileInputNum2,pUser);           
          printf("输出用户所写的信息/n");
          printf("%s/n", szfile); 
          fclose(pUser); 
         }  
         else
          printf("你所查找的用户信息无法返回信息/n"); 
        }
       }     
       break;
      default:
       printf("您的输入有误,程序将回到主界面/n");       
      }
      break;
      case 'h':
      case 'H':
       system("cls");
       HelpFace();
       gotoxy(4,22);
       Time();
       gotoxy(40,22);
       printf("当前用户是:%s",stFileInput.szUserLoadName);
       gotoxy(25,2);
       printf("欢迎%s使用帮助录入界面",stFileInput.szUserLoadName);  
       break;
      case 'U':
      case 'u':
       ShowUserMenu();
       break;
      case 's':
      case 'S':
       ShowUserContent();
       break;
      default:
       system("cls");
       printf("您刚才的输入有误,请重新登陆.../n");
       Sleep(1000);
       UserLoad();
     }
     flag=1;
     break;
 }
 
     
  }
  
 
  fclose(pstream);

  if (flag==0)
  {
   printf("您输入的帐号或密码错误,程序将退回到初始界面");
   int k;
   printf("/n  〓程序加载中>>>> ");
   for (k=1;k<=25;k++)
   {
    printf("■");
    Sleep(100);
   }
   system("cls");
   ShowmainFace();
   gotoxy(3,22);
   Time();
         gotoxy(4,6);
  }
       

 }
 fflush(stdin);
 
}

// -------------------------------------------
// 函数名  :文件录入函数
// 函数作用:用户可以输入一定量的文字,并把文字保存在相关的文件中
// ----------------------------------------------
//
void FileInput(char szRecName[20])
{
    FILE *pstream,*pFileInputNum;
 int i,j=0,y=0;
 char szMID1[20],szMID3[20];
 char cYON;
 int nFileInputNum=0;
 int nFileInputNum1=0;

 strcpy(szMID1,szRecName);
 strcpy(szMID3,szRecName);

 if((pFileInputNum=fopen(strcat(szMID1,"Input.txt"),"rt")) != NULL )
 {
  
  fscanf(pFileInputNum,"%d",&nFileInputNum1);
  fclose(pFileInputNum);
 }
 else
  printf( "Problem opening the file/n" );
 
 void FrameShow(int x, int y, int width, int height);
 void ClearMap(int x,int y,int num);
 
    if((pstream=fopen(strcat(szRecName,".txt"),"a+t")) != NULL )
    {
  char chWord='0';
  char* pchWord = NULL,* pchWord1 = NULL;
  pchWord = (char*)malloc(sizeof(char)*2);
  gotoxy(15,6);
  printf("请输入您要输入的数据:");
  FrameShow(15,7,27,15);
  gotoxy(17,8);
  *pchWord = getche();
  for (i=1;chWord!=27;i++)
  {
   *(pchWord+i) = getche();
   if ((*(pchWord+i)!=27)&&(*(pchWord+i)!=13)&&(*(pchWord+i)!=8))
   {
    pchWord1 = (char*)malloc(sizeof(char)*(2+i));
    for (j=0;j<2+i;j++)
     *(pchWord1+j) = *(pchWord+j);
    *(pchWord1+i+1) = '/0';
    free(pchWord);
    pchWord = (char*)malloc(sizeof(char)*(2+i));
    for (j=0;j<2+i;j++)
     *(pchWord+j) = *(pchWord1+j);
    free(pchWord1);
   }      
   else
    if (*(pchWord+i)==13)
    {
     *(pchWord+i)=NULL; 
     i--;
     gotoxy(15,8+(++y));
    }
    else
     if (*(pchWord+i)==8)
     {
      *(pchWord+i)=NULL; 
      ClearMap(15+i,7,1);
      i-=2;
     }
     else
      if (*(pchWord+i)==27)
      {
         break;
      }
        
  }
  *(pchWord+i) = '/0';
  gotoxy(17,8+(++y));
  nFileInputNum=i;
  printf("您输入了%d个字符/n",nFileInputNum);   
        fputs(pchWord,pstream);
  gotoxy(17,8+(++y));
  printf("你是否要保存本次所写的内容");
  gotoxy(19,8+(++y));
  printf("是请输入S,不是请输入N");
/*  fputc('/n',pstream);*/
  gotoxy(17,8+(++y));
  fflush(stdin);
  scanf("%c",&cYON);
  if (cYON=='s'||cYON=='S')
  {
   fclose(pstream);
   gotoxy(17,8+(++y));
   printf("你本次所写的内容被成功录入!!");
  }
   else
   {
    gotoxy(17,8+(++y));
    printf("你本次所写的内容没有被录入!!");
   }
  
 }
    else
  printf( "Problem opening the file/n" );

 if((pFileInputNum=fopen(strcat(szMID3,"Input.txt"),"wt")) != NULL )
 {
        nFileInputNum1=nFileInputNum1+nFileInputNum;
  fprintf(pFileInputNum,"%d",nFileInputNum1);
  fclose(pFileInputNum);
 }
 else
  printf( "Problem opening the file/n" );

}

// -------------------------------------------
// 函数名  :画框函数
// 函数作用:通过实参来画出一定大小和位置的矩形框
// ----------------------------------------------
//
void FrameShow(int x, int y, int width, int height)

    for(int nI = 0; nI < height; nI++)  //行数   
    {   
        for(int nJ = 0; nJ < width*2; nJ += 2) //列数,width*2中文符号占两位    
        {    
            gotoxy(x + nJ, y + nI); //调用我们前面的函数进行光标的定位    
            if(nI == 0 || nJ == width*2 - 2 || nJ == 0 || nI == height - 1) //只打印四个边     
            {     
                if(nI == 0 && nJ == 0 ) //左上的拐角      
                {      
                    printf("┏");      
                }    
                else if(nI == 0 && nJ == width * 2 - 2)      
                {      
     printf("┓");//右上的拐角      
                }     
                else if(nI == height - 1 && nJ == 0)      
                {      
                    printf("┗");//左下的拐角      
                }     
                else if(nI == height - 1 && nJ == width*2 - 2)      
                {      
                    printf("┛");//右下的拐角      
                }     
                else if(nI == 0 || nI == height - 1)     
                {      
                    printf("━");       
                }     
                else      
                {      
                    printf("┃");      
                }     
            }    
        }   
        printf("/n");  
    }
}

// -------------------------------------------
// 函数名  :清除函数
// 函数作用:清楚指定区域的内容
// ----------------------------------------------
//
void ClearMap(int x,int y,int num)
{
 HANDLE consolehwnd = GetStdHandle(STD_OUTPUT_HANDLE);  
    COORD  MainPos={x, y};
    FillConsoleOutputCharacter(consolehwnd, ' ',num, MainPos, 0);
}

// -------------------------------------------
// 函数名  :显示欢迎界面
// 函数作用:用来欢迎用户的使用界面
// ----------------------------------------------
//
void WelcomeFace()
{
 int i=0,j=0,k=0; 
 HANDLE consolehwnd = GetStdHandle(STD_OUTPUT_HANDLE);

 system("title 软件欢迎界面,谢谢观看 ");
 for (i=2,k=1;i<24;i+=2,k++)
 {
  for (j=i;j<82-i;j+=2)//星2个字节
  {
   SetConsoleTextAttribute(consolehwnd,j%15+1);
   gotoxy(j-1,k);
   printf("◎");
   Sleep(1);
  }
  
  for ( j=1;j<26-i;j++)
  {
   SetConsoleTextAttribute(consolehwnd,j%15+1);
   gotoxy(81-i,j+k-1);
   printf("◎");
   Sleep(1);
  }

  for ( j=81-i;j>i-1;j-=2)
  {
   SetConsoleTextAttribute(consolehwnd,j%15+1);
   gotoxy(j,24-k);
   printf("◎");
   Sleep(1);
  }
  
  for ( j=24;j>i;j--)
  {
   SetConsoleTextAttribute(consolehwnd,j%15+1);
   gotoxy(i-1,j-k);
   printf("◎");
   Sleep(1);
  }
  
 }

 for (i=2,k=1;i<24;i+=2,k++)
 {
  for (j=i;j<82-i;j+=2)//星2个字节
  {
   HANDLE consolehwnd = GetStdHandle(STD_OUTPUT_HANDLE);  
   COORD  MainPos={j-1, k-1};
            FillConsoleOutputCharacter(consolehwnd, ' ',2, MainPos, 0);
   Sleep(1);
  }
 
  for ( j=1;j<26-i;j++)
  {
   HANDLE consolehwnd = GetStdHandle(STD_OUTPUT_HANDLE);  
   COORD  MainPos={80-i, j+k-1};
            FillConsoleOutputCharacter(consolehwnd, ' ',2, MainPos, 0);
   Sleep(1);
  }
  
  for ( j=81-i;j>i-2;j-=2)
  {
   HANDLE consolehwnd = GetStdHandle(STD_OUTPUT_HANDLE);  
   COORD  MainPos={j,23-k};
            FillConsoleOutputCharacter(consolehwnd, ' ',2, MainPos, 0);
   Sleep(1);
  }
  
  for ( j=24;j>i-1;j--)
  {
   HANDLE consolehwnd = GetStdHandle(STD_OUTPUT_HANDLE);  
   COORD  MainPos={i-2,j-k};
            FillConsoleOutputCharacter(consolehwnd, ' ',2, MainPos, 0); 
   Sleep(1);
  }
  
 }
}

// -------------------------------------------
// 函数名  :用户权限登陆,和整个程序的控制函数
// 函数作用:获取权限,登陆程序,完成相关的程序操作
// ----------------------------------------------
//
void Fristmain()
{
 char cM,k;
 char szName[20];

 memset(szName,0,20);
 system("title 欢迎界面:请输入本软件的作者!(没经过授权请联系作者所要授权) ");
 printf("请输入本软件的作者:");
 gets(szName);
 if ((!strcmp(szName,"jinkailong"))||(!strcmp(szName,"金开龙")))
 {
 
  HideCursor();
  for (int d=0;d<2;d++)
  {
   system("title 欢迎使用    请你先登陆系统 ");
   Sleep(1000);
   system("title 欢迎使用         以便你的使用");
   Sleep(1000);
  }
  system("title 欢迎使用 请输入U进行用户登陆,输入H查看帮助信息!");
  system("color f0");
  system("cls");
  do
  {
   ShowCursor();
   ShowmainFaceFrist();
   gotoxy(3,22);
   Time();
   gotoxy(3,5);
   
   fflush(stdin);
   gotoxy(2,24);
   scanf("%c",&cM);
   
   if (cM=='U'||cM=='u')
   {
    system("cls");
    ShowmainFaceFrist();
    ShowUserMenu();
    gotoxy(35,19);
    printf("是否要继续本程序操作,");
    gotoxy(35,20);
    printf("确定请输入Y或y,要是想退出请按N或n../n");
    
    fflush(stdin);
    gotoxy(35,23);
    scanf("%c",&k);
    
    if (k=='n'||k=='N')
    {
     gotoxy(35,8);
     printf("谢谢您的使用本程序...../n");
     break;
    }
    
   }
   else
    if (cM=='H'||cM=='h')
    {
     HelpFace();
     gotoxy(35,18);
     printf("是否要继续本程序操作,");
     gotoxy(35,19);
     printf("确定请输入Y或y,要是想退出请按N或n../n");
     
     fflush(stdin);
     gotoxy(35,20);
     scanf("%c",&k);
     
     if (k=='n'||k=='N')
     {
      gotoxy(35,23);
      printf("谢谢您的使用本程序...../n");
      break;
     }
    }
    
    system("cls");
    
  } while (k=='Y'||k=='y');
  
  gotoxy(35,24);
  
 }
}

int main(int argc, char* argv[])
{
 WelcomeFace();

 Fristmain();

    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值