導航:首頁 > 編程語言 > 人性的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個源代碼相關的資料

熱點內容
怎麼查看工作目錄里的文件名 瀏覽:525
華為黃app怎麼下載 瀏覽:342
禁用U盤怎麼傳輸文件 瀏覽:88
wifi萬能密碼舊版 瀏覽:340
linux如何傳文件虛擬機 瀏覽:929
word支持的文件類型 瀏覽:286
sfc轉移號怎麼編程 瀏覽:860
平面設計教程的書籍 瀏覽:676
掃描後的文件還能改么 瀏覽:21
微信代碼怎麼沒用了 瀏覽:65
2013款卡羅拉原裝導航怎麼升級 瀏覽:860
微信掃描下載蘋果app 瀏覽:29
70煉金術升級 瀏覽:862
C文件檢驗 瀏覽:101
IccID未知是有網路鎖嗎 瀏覽:101
蘋果5s怎麼定位蘋果6手機 瀏覽:556
蘋果手機港版怎麼解鎖 瀏覽:189
根據xml規則讀取excel文件 瀏覽:28
網路刪除文件 瀏覽:325
蘋果怎麼共享wifi網路列印機 瀏覽:368

友情鏈接