头文件getputch.h

/*
* getputch.c
*/
/* 用于getch/putch的通用头文件"getputch.h" */ #ifndef __GETPUTCH #define __GETPUTCH #if defined(_MSC_VER) || (__TURBOC__) || (LSI_C) /* MS-Windows/MS-DOS(Visual C++, Borland C++, LSI-C 86 etc ...)*/ #include <conio.h> static void init_getputch(void) { /* 空 */ } static void term_getputch(void) { /* 空 */ } #else /* 提供了Curses库的UNIX/Linux/OS X环境 */ #include <curses.h> #undef putchar
#undef puts
#undef printf
static char __buf[]; /*--- _ _putchar:相当于putchar函数(用“换行符+回车符”代替换行符进行输出)---*/
static int __putchar(int ch)
{
if (ch == '\n')
putchar('\r');
return putchar(ch);
} /*--- putch:显示1个字符,清除缓冲区 ---*/
static int putch(int ch)
{
int result = putchar(ch); fflush(stdout);
return result;
} /*--- _ _printf:相当于printf函数(用“换行符+回车符”代替换行符进行输出)---*/
static int __printf(const char *format, ...)
{
va_list ap;
int count; va_start(ap, format);
vsprintf(__buf, format, ap);
va_end(ap); for (count = ; __buf[count]; count++) {
putchar(__buf[count]);
if (__buf[count] == '\n')
putchar('\r');
}
return count;
} /*--- _ _puts:相当于puts函数(用“换行符+回车符”代替换行符进行输出)---*/
static int __puts(const char *s)
{
int i, j; for (i = , j = ; s[i]; i++) {
__buf[j++] = s[i];
if (s[i] == '\n')
__buf[j++] = '\r';
}
return puts(__buf);
} /*--- 库初始处理 ---*/
static void init_getputch(void)
{
initscr();
cbreak();
noecho();
refresh();
} /*--- 库终止处理 ---*/
static void term_getputch(void)
{
endwin();
} #define putchar __putchar
#define printf __printf
#define puts __puts #endif #endif

消除一个字符串:

/*
*type_erase_string.c
*/
#include<time.h>
#include<ctype.h>
#include<stdio.h>
#include<string.h>
#include"getputch.h" int main()
{
int i;
char *str = "How do you do?";
int len = strlen(str);
clock_t start, end;
init_getputch();
printf("please input as same\n");
printf("%s\n", str); fflush(stdout); start = clock();
for (i = ; i < len; i++)
{
int ch;
do
{
ch = getch(); //从键盘读取信息,getputch.h函数
if (isprint(ch))
{
putch(ch);
if (ch != str[i])
{
putch('\b'); //光标退一格
}
}
}while (ch != str[i]);
} end = clock();
printf("\nspend time %1.fs. \n", (double)(end - start) / CLOCKS_PER_SEC); //ubuntu14显示不出来,应该可以用localtime来显示
term_getputch();
return ;
}

消除已经输出的字符

/*
*type_erase_string_put.c
*/
#include<stdio.h>
#include<time.h>
#include<stdio.h>
#include<string.h>
#include"getputch.h" int main()
{
int i;
char *str = "How do you do?";
int len = strlen(str);
clock_t start, end;
init_getputch();
printf("please input as following\n");
start = clock();
for (i = ; i < len; i++)
{
//显示str[i]以后的字符并把光标返回到开头 \r 回车符
printf("%s \r", &str[i]);
fflush(stdout);
while(getch() != str[i])
;
} end = clock();
printf("spending time %.1f s \n", (double)(end-start)/CLOCKS_PER_SEC);
term_getputch();
return ;
}

输入多个字符串

/*
*type_put_more.c
*/
#include<stdio.h>
#include<time.h>
#include<string.h>
#include"getputch.h" #define QNO 12 int main()
{
char *str[QNO] = {"book", "computer", "default", "comfort", "monday",
"power", "light", "music", "programming",
"dog", "video", "include"}; int i, stage;
clock_t start, end; init_getputch();
printf("Starting practice type. \n");
printf("please enter space to start.\n"); while(getch() != ' ')
; start = clock(); for (stage = ; stage < QNO; stage++)
{
int len = strlen(str[stage]);
for (i = ; i < len; i++)
{
//显示str[stage][i]以后的字符并把光标返回到开头
printf("%s \r", &str[stage][i]);
fflush(stdout);
while (getch() != str[stage][i])
;
}
} end = clock(); printf("\rSpending time %.1f second . \n", (double)(end - start)/CLOCKS_PER_SEC);
term_getputch();
return ;
}

打乱出题顺序,使用数组来标识出题顺序

/*
*type_random.c
*/
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<time.h>
#include"getputch.h" #define QNO 12
#define swap(type, x, y) do{type t = x; x = y; y = t;}while(0) int main()
{ char *str[QNO] = {"book", "computer", "default", "comfort", "monday",
"power", "light", "music", "programming",
"dog", "video", "include"}; int i, stage;
int qno[QNO]; //出题顺序
clock_t start, end;
init_getputch();
srand(time(NULL)); //设置随机数种子 for (i = ; i < QNO; i++)
{
qno[i] = i;
} for (i = QNO - ; i > ; i--) //打乱出题顺序
{
int j = rand()% (i + );
if (i != j)
{
swap(int , qno[i], qno[j]);
}
} printf("Starting type practice.\n");
printf("Starting after entering space .\n");
while (getch() != ' ')
; start = clock();
for (stage = ; stage < QNO; stage++)
{
int len = strlen(str[qno[stage]]);
for (i = ; i < len; i++)
{
printf("%s \r", &str[qno[stage]][i]);
fflush(stdout);
while (getch() != str[qno[stage]][i])
;
}
} end = clock();
printf("\r Costing time : %.1f seconds. \n", (double)(end - start)/CLOCKS_PER_SEC); term_getputch();
return ; }

交换指针打乱出题顺序:

/*
*type_random_2.c
*/
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<time.h>
#include"getputch.h" #define QNO 12 #define swap(type, x, y) do {type t = x; x = y; y = t;} while(0) int main()
{ char *str[QNO] = {"book", "computer", "default", "comfort", "monday",
"power", "light", "music", "programming",
"dog", "video", "include"};
int i, stage;
clock_t start, end; init_getputch();
srand(time(NULL)); for (i = QNO - ; i > ; i--)
{
int j = rand()%(i+);
if (i != j)
{
swap(char *, str[i], str[j]);
}
} printf("Starting type practice\n");
printf("Start after entering space. \n");
while (getch() != ' ')
;
start = clock(); for (stage = ; stage < QNO; stage++)
{
int len = strlen(str[stage]);
for (i = ; i < len; i++)
{
printf("%s \r", &str[stage][i]);
fflush(stdout);
while(getch() != str[stage][i])
;
}
} end = clock();
printf("\r Costing time : %.1f seconds \n", (double)(end-start)/CLOCKS_PER_SEC);
term_getputch();
return ; }

键盘联想字符:输出键盘一块区域的字符,隐藏一个,打出隐藏的这个字符

/*
*type_keyboard.c
*/
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<time.h>
#include"getputch.h" #define NO 3
#define KTYPE 16 int main()
{
char *kstr[] = {"", "67890-=",
"!@#$%", "^&*()_+",
"qlert", "yuiop[]\\",
"QWERT", "YUIOP{}|",
"asdfg", "hjkl;'",
"ASDFG", "HJKL:\""
"zxcvb", "nm,./",
"ZXCVB", "NM<>?"}; int i, stage; clock_t start, end; init_getputch();
srand(time(NULL)); printf("Starting practice type \n");
printf("please use ? to hidden type. \n");
printf("Start entering space\n"); fflush(stdout);
while(getch() != ' ')
; start = clock(); for (stage = ; stage < NO; stage++)
{
int k, p, key;
char temp[]; do
{
k = rand() % KTYPE;
p = rand() % strlen(kstr[k]);
key = kstr[k][p];
}while(key == ' '); strcpy(temp, kstr[k]);
temp[p] = '?';
printf("%s", temp);
fflush(stdout);
while(getch() != key)
; putchar('\n');
} end = clock();
printf("Costing time : %.1f seconds. \n", (double)(end - start)/CLOCKS_PER_SEC); term_getputch();
return ;
}

TypeWriting的更多相关文章

  1. 【英语魔法俱乐部——读书笔记】 1 初级句型-简单句(Simple Sentences)

    第一部分 1 初级句型-简单句(Simple Sentences):(1.1)基本句型&补语.(1.2)名词短语&冠词.(1.3)动词时态.(1.4)不定式短语.(1.5)动名词.(1 ...

  2. A debugger is already attached

    Today is the last day that all the laptops of winXP OS should be upgrade to WIN7. After updated. whe ...

  3. 用Python来进行词频统计

    # 把语料中的单词全部抽取出来, 转成小写, 并且去除单词中间的特殊符号 def words(text): return re.findall('[a-z]+', text.lower()) def ...

  4. HDU5470 Typewriter (SAM+单调队列优化DP)

    Typewriter Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Tota ...

随机推荐

  1. MongoDB自学------(2)创建删除数据库及集合

    一.创建数据库 二.查看所有数据库 三.删除数据库 四.创建集合 五.删除集合 六.集合用法介绍 1.创建集合 2.删除集合 下一篇链接:https://www.cnblogs.com/LinHuCh ...

  2. IDEA设置外部比对工具Beyond Compare

    设置IDEA使用外部的比对工具,比如Beyond Compare,其实很简单,但是可能好几年才会设置一次,比如换工作的时候,所以记录下来 可以通过菜单File-Settings 或者直接快捷键ctrl ...

  3. Expression Tree上手指南 (一)【转】

    大家可能都知道Expression Tree是.NET 3.5引入的新增功能.不少朋友们已经听说过这一特性,但还没来得及了解.看看博客园里的老赵等诸多牛人,将Expression Tree玩得眼花缭乱 ...

  4. Kubernetes DaemonSet(部署守护进程)

    Kubernetes DaemonSet(部署守护进程) • 在每一个Node上运行一个Pod• 新加入的Node也同样会自动运行一个Pod 应用场景:Agent 官方文档:https://kuber ...

  5. 【MySQL】条件查询之排序聚合分组分页查询

    排序查询 语法:order by 子句 order by 排序字段1 排序方式1 , 排序字段2 排序方式2... 排序方式: ASC:升序,默认的. DESC:降序. 注意: 如果有多个排序条件,则 ...

  6. dubbo(提供者、消费者)基于java的实现

    1.安装好jdk.zookeeper以后可以尝试开发代码进行dubbo的学习和练习. 首先创建Dubbo的Provider配置.创建一个maven project工程. RPC框架,不希望Consum ...

  7. POS时机未到,POW强攻是实现全球货币的正确道路

    POS时机未到,POW强攻是实现全球货币的正确道路 取代现今的货币体系的正确进攻方式是POW强攻,现在的货币是由力量背书的,以后的货币也是由力量背书的,只有因造币耗费的力量超过了所有其它力量的时候才能 ...

  8. EF操作与Linq写法记录

    项目总结:EF操作与Linq写法记录 1.EF引入 新建一个MVC项目之后,要引用EF框架,可以按照以下步骤进行: 1),在Models中添加项目 2),选择Entity Data Model,并重新 ...

  9. Asp.Net MVC 的19个管道事件

    httpApplication调用ProcessRequest方法,内部执行19个管道事件,如下 BeginRequest  开始处理请求 AuthenticateRequest 授权验证请求开始,获 ...

  10. HTTP Protocol

    HTTP协议 1      HTTP请求状态码 当用户试图通过 HTTP 访问一台正在运行 Internet 信息服务 (IIS) 的服务器上的内容时,IIS 返回一个表示该请求的状态的数字代码.状态 ...