日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

c语言作业做出金山打字功能,goldmountain.c

發布時間:2024/9/19 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 c语言作业做出金山打字功能,goldmountain.c 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

#include

#include

#include

#include

#include

#define NR(x) sizeof(x)/sizeof(x[0])

//在終端上打印信息

#define Print_Info_To_console(str,hOut,pos,x,y,color_type) \

SetConsoleTextAttribute(hOut, color_type); \

pos.X = x;\

pos.Y = y ;\

SetConsoleCursorPosition(hOut,pos); \

printf("%s",str);

//清屏

#define ClearScreen() \

system("cls");

#define TITLE "金山打字通"

enum

{

LEFT = 1 ,

RIGHT ,

BACKSPACE ,

ESC ,

Char,

};

int iindex = 0 ;

int max = 0 ;

char buffer[1024] = {0} ;

int Get_User_input(HANDLE hOut,char *ch) ;

void Show_string(HANDLE hOut,const char *text) ;

//窗口初始化

void HANDLE_init(HANDLE hOut);

//定義設置光標結構體變量

CONSOLE_CURSOR_INFO cci;

//定義默認的坐標位置

COORD pos = {0,0};

int main(void)

{

char *text = "WelCome to School ... Good Good Work ,Day Day Up !" ;

char ch ;

int ret ;

HANDLE hOut;

hOut = GetStdHandle(STD_OUTPUT_HANDLE);

HANDLE_init(hOut);

printf("\n%s\n",text);

Show_string(hOut,text);

while(1)

{

if(max >= strlen(text))

break ;

ret = Get_User_input(hOut,&ch) ;

if(ret == ESC)

break ;

Show_string(hOut,text);

}

//關閉窗口句柄

CloseHandle(hOut);

return 0 ;

}

//窗口初始化

void HANDLE_init(HANDLE hOut)

{

SetConsoleTitleA(TITLE);

//獲取當前的句柄---設置為標準輸出句柄

//獲取光標信息

GetConsoleCursorInfo(hOut, &cci);

//設置光標大小

pos.X = 0 ;

pos.Y = 2 ;

cci.dwSize = 1;

//設置光標不可見 FALSE

cci.bVisible = 0;

//設置(應用)光標信息

SetConsoleCursorInfo(hOut, &cci);

}

static int __Get_User_input(HANDLE hOut,char *ch)

{

char tmp ;

int type = Char ;

//關閉回顯

pos.X = 0 ;

pos.Y = 2 ;

GetConsoleCursorInfo(hOut, &cci);

cci.dwSize = 100;

cci.bVisible = 0;

SetConsoleCursorInfo(hOut, &cci);

tmp = getch() ;

switch(tmp)

{

case 27 : type = ESC ; break ;

case 8 : type = BACKSPACE ; break ;

case 75 : type = LEFT ; break ;

case 77 : type = RIGHT; break ;

}

*ch = tmp ;

//打開回顯

pos.X = 0 ;

pos.Y = 2 ;

GetConsoleCursorInfo(hOut, &cci);

cci.dwSize = 100;

cci.bVisible = 1;

SetConsoleCursorInfo(hOut, &cci);

return type ;

}

int Get_User_input(HANDLE hOut,char *ch)

{

int type ;

type = __Get_User_input(hOut,ch);

switch(type)

{

case Char :

if(buffer[iindex] == '\0' )

buffer[iindex] = *ch ;

else

{

memmove(buffer+iindex+1 , buffer+iindex , max-iindex) ;

buffer[iindex] = *ch ;

}

iindex ++ ; max ++ ; break ;

case LEFT : if(iindex > 0) iindex -- ; break ;

case RIGHT : if(iindex < max) iindex ++ ; break ;

case BACKSPACE :

if(iindex > 0){

memmove(buffer+iindex-1 , buffer+iindex , max-iindex) ;

iindex -- ;

max -- ;

}

break ;

case ESC : return ESC ;

}

return 0 ;

}

void Show_string(HANDLE hOut,const char *text)

{

system("cls") ;

printf("\n%s\n",text) ;

int i ;

int errno_Num = 0 ;

for(i = 0 ; i < max ; i++)

{

if(buffer[i] == text[i])

{

SetConsoleTextAttribute(hOut, FOREGROUND_GREEN | 0x8);

printf("%c",buffer[i]);

}

else

{

SetConsoleTextAttribute(hOut, FOREGROUND_RED | 0x8);

printf("%c",buffer[i]);

errno_Num++ ;

}

}

pos.X = 0 ;

pos.Y = 2 ;

cci.dwSize = 100;

cci.bVisible = 1 ;

SetConsoleCursorPosition(hOut,pos);

SetConsoleCursorInfo(hOut, &cci);

SetConsoleTextAttribute(hOut,FOREGROUND_GREEN | 0x8);

pos.X = 0;

pos.Y = 15 ;

SetConsoleCursorPosition(hOut,pos);

printf("錯誤的個數:%d", errno_Num) ;

pos.X = 0;

pos.Y = 16 ;

SetConsoleCursorPosition(hOut,pos);

printf("總個數:%d", (int)strlen(text)) ;

pos.X = 0;

pos.Y = 17 ;

SetConsoleCursorPosition(hOut,pos);

printf("輸入個數:%d", max) ;

pos.X = 0;

pos.Y = 18 ;

SetConsoleCursorPosition(hOut,pos);

printf("錯誤率:%.2f%%",((float)errno_Num)/((float)max)*100) ;

pos.X = iindex + 1 ;

pos.Y = 2 ;

cci.dwSize = 100;

cci.bVisible = 1 ;

SetConsoleCursorPosition(hOut,pos);

SetConsoleCursorInfo(hOut, &cci);

fflush(stdout);

}

一鍵復制

編輯

Web IDE

原始數據

按行查看

歷史

總結

以上是生活随笔為你收集整理的c语言作业做出金山打字功能,goldmountain.c的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。