C语言编写打字程序

 

大致的效果如上,这个小程序可以更改打字的颜色,通过配置文件读取。

 

/* 时间: 2019/2/29, 作者: Y.W.R */
// TypeWriting Program -pseudocode(伪代码)
// First it reads the configuration file, and load configuration information
// This includes (ambient color, article path). Then provide a selection of
// articles, Enter typing mode. Finally, collect relevant information.
// 首先读取配置文件,读取配置信息,这包括(环境颜色,文章路径)。
// 然后提供可选择的文章,进入打字模式。最后统计相关信息。

#include <io.h>
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <windows.h>
#define MAXLEN 4801 // 最大长度: 4800
#define PAGELEN 960 // 页长度: 80 * 12
#define MAXCOLOR 5  // 颜色总数
#define LINE 40 // 菜单行长度
#define COLS 10 // 菜单列长度

const char Version[] =
{"Copyright by Ms.Y.r version: v0.0.1"};

const char * MATCH_FILE = ".\\default.conf";
const char * ARTICLE = ".\\paper\\";

typedef struct information {
    int length;
    int n_complete;
    float n_correct;
    float n_wrong;
} Infor;

typedef struct environment {
    WORD BACK_COLOR;
    WORD TRUE_COLOR;
    WORD FALSE_COLOR;
    WORD UNLABLED_COLOR;
    WORD TEXT_COLOR;
} Envir;

/** 控制台可配置属性
* #define FOREGROUND_BLUE	      1
* #define FOREGROUND_GREEN	      2
* #define FOREGROUND_RED	      4
* #define FOREGROUND_INTENSITY	  8
-----------------------------------
* #define BACKGROUND_BLUE	     16
* #define BACKGROUND_GREEN	     32
* #define BACKGROUND_RED	     64
* #define BACKGROUND_INTENSITY	128
*/

HANDLE hStdout, hStdin;
CONSOLE_SCREEN_BUFFER_INFO csbiInfo;

char words[MAXLEN];
char article[COLS][LINE - 2];
int mark = 1;

/* 显示方框 */
void Orthgon();
/* 显示文章 */
void ShowArtice(int n_list, Infor * wString);
/* 获取选择 */
int ChoiceArtice(int n_list);
/* 查找文章 */
int FindFile();
/* 载入颜色配置 */
bool MatchText(Envir * wColor);
/* 载入文章数据 */
bool LoadFile(char * pFile, Infor * wString);
/* 设置光标模式 */
void SetCurInfo(BOOL isVisible);
/* 进入打字模式 */
bool TypeWrite(Envir * wColor, Infor * wString);
/* 显示文章数据 */
void ShowText(int * flags, WORD cColor);
/* 设置屏幕颜色 */
void SetScreen(WORD cColor, COORD coordScreen, DWORD dwConSize);
/* 显示打字数据 */
void ShowWriting(Envir * wColor, Infor * wString);
void ShowVer(COORD cPos);

int main()
{
    Infor wString = { 0 };
    Envir wColor = { 0 };
    SetConsoleTitle("TypeWriting - 无文章");

    hStdout = GetStdHandle(STD_OUTPUT_HANDLE);
    hStdin = GetStdHandle(STD_INPUT_HANDLE);

    if (hStdout == INVALID_HANDLE_VALUE ||
        hStdin == INVALID_HANDLE_VALUE)
    {
        MessageBox(NULL, "GetStdHandle", "Error", MB_OK);
        return 1;
    }

    COORD coordHome = { 0,0 };
    COORD coordSize = { 80,25 };
    SetConsoleScreenBufferSize(hStdout, coordSize);

    if (! GetConsoleScreenBufferInfo(hStdout, &csbiInfo))
        return 1;

    if(! MatchText(&wColor))
    {
        MessageBox(NULL, "Read configuration", "Error", MB_OK);
        return 1;
    }

    int select, f_number;
    if (! (f_number = FindFile()))
    {
        MessageBox(NULL, "No File", "Error", MB_OK);
        return 1;
    }

    int choices;
    char * pq = NULL;
    char szTitle[81] = { 0 };


    while (1)
    {
        SetCurInfo(fa
  • 0
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值