導航:首頁 > 編程語言 > 人性的14個源代碼

人性的14個源代碼

發布時間:2023-08-19 23:38:46

A. 求幾個比較有趣,簡單的C語言源代碼 小白自己敲著練一下手感

最簡單的模擬計時器:

#include<stdio.h>

#include<conio.h>

#include<windows.h>

int m=0,s=0,ms=0; //m是分 s是秒 ms是毫秒

//以下是5個自編函數

void csh( ); //初始化界面

void yinc(int x,int y); //隱藏游標的函數(y值設為0就會隱藏)

void jishi( ); //計時器運行(每100毫秒變化一次)

void Color (short x, short y); //設定顏色的函數(y設為0就是黑底)

void gtxy (int x, int y); //控制游標位置的函數

int main( ) //主函數

{ csh( );

getch( );

while(1)

{ jishi( );

Sleep(100); //間隔100毫秒

if( kbhit( ) )break; //有鍵按下就退出循環

}

return 0;

}

void csh( ) //初始化界面

{Color(14,0); //設定淡黃字配黑底

printf(「 計時器」);

Color(10,0); //設定淡綠字配黑底

printf(" ┌───────────┐");

printf(" │ │");

printf(" └───────────┘");

gtxy(10,4); //游標到屏幕第10列4行處輸出

Color(7,0); //恢復白字黑底

printf(" 00:00:00 ");

yinc(1,0 ); //隱藏游標(yinc代表隱藏)

return;

}

void jishi( ) //計時器運行

{ms+=1;

if(ms==10){s+=1;ms=0;}

if(s==60){m+=1;s=0;}

gtxy(10,4);

Color(9,0); //設定淡藍字配黑底

if(m>9) printf(" %d:",m);

else printf(" 0%d:",m);

Color(14,0); //設定淡黃字配黑底

if(s>9) printf("%d:",s);

else printf("0%d:",s);

Color(12,0); //設定淡紅字配黑底

printf("0%d",ms);

}

void gtxy (int x, int y) //控制游標位置的函數

{ COORD pos;

pos.X = x;

pos.Y = y;

SetConsoleCursorPosition ( GetStdHandle (STD_OUTPUT_HANDLE), pos );

}

void Color (short ForeColor= 7, short BackGroundColor= 0) //設定顏色的函數

{ HANDLE handle = GetStdHandle ( STD_OUTPUT_HANDLE );

SetConsoleTextAttribute ( handle, ForeColor + BackGroundColor * 0x10 );

}

void yinc(int x,int y) //隱藏游標的設置(gb代表游標)

{ CONSOLE_CURSOR_INFO gb={x,y}; //x為1-100,y為0就隱藏游標

SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE), &gb);

}

閱讀全文

與人性的14個源代碼相關的資料

熱點內容
網路上的表情是什麼意思 瀏覽:819
exosshow哪個app好 瀏覽:691
clr資料庫程序集優點 瀏覽:919
手機編輯sql文件 瀏覽:355
裝了w8系統d盤文件沒了 瀏覽:509
殺毒軟體刪除的文件怎麼找回 瀏覽:853
novalct大屏配置文件 瀏覽:137
iphone磁吸數據線哪個好 瀏覽:279
終結者遠程式控制制軟體賬號密碼 瀏覽:53
chttp發送文件路徑 瀏覽:558
網站類論文功能設計模塊怎麼寫 瀏覽:933
斗魚伴侶看不到qq游戲 瀏覽:401
5s怎麼看運營商版本 瀏覽:410
導出選定網格到外部文件 瀏覽:508
vrmkv文件沒有聲音 瀏覽:447
惠普電腦u盤裝系統視頻教程 瀏覽:906
ufo文件查看 瀏覽:399
什麼市資料庫的安全性 瀏覽:335
fanucotd數控車床如何編程 瀏覽:62
蘋果開機時白屏黑蘋果 瀏覽:559

友情鏈接