轉載的一些常用的C函數,還有些用途

 

C系統函數庫些許

 

--------------------------------------------------------------------------------

 

  原型:extern void clrscr(void);

                        extern void ClearScreen(void);

                        用法:#i nclude <system.h>

                        功能:清屏

                        說明:清除屏幕緩衝區及液晶顯示緩衝區

                        光標位置回到屏幕左上角。

                        舉例:

                        // clrscr.c

                        i nclude <system.h>

                        main()

                        {

                        clrscr();

                        textmode(0x00);

                        printf("Press a key");

                        getchar();

                        ClearScreen();

                        printf("Another Screen");

--------------------------------------------------------------------------------  原型:extern int getkey(void);

                        用法:#i nclude <system.h>

                        功能:讀鍵

                        說明:功能同getchar

                        舉例:

                        // getkey.c

                        i nclude <system.h>

                        main()

                        {

                        int c;

                        clrscr();

                        printf("Press key...");

                        while((c=getkey())!='Q')

                        {

                        clrscr();

                        printf("key: %c/nvalue: %x",c,c);

--------------------------------------------------------------------------------  原型:extern void sleep(unsigned int sec);

                        用法:#i nclude <system.h>

                        功能:短暫延時

                        說明:延時sec

                        舉例:

                        // sleep.c

                        i nclude <system.h>

                        main()

                        {

                        int c;

                        clrscr();

                        printf("/nHello, world!");

                        sleep(1);

                        clrscr();

                        printf("/nHi, guys");

--------------------------------------------------------------------------------  原型:extern void delay(unsigned int msec);

                        用法:#i nclude <system.h>

                        功能:短暫延時

                        說明:延時msec*4毫秒

                        舉例:

                        // delay.c

                        i nclude <system.h>

                        main()

                        {

                        int c;

                        clrscr();

                        printf("/nHello, world!");

                        delay(250);    // 250*4=1000msec=1sec

                        clrscr();

                        printf("/nHi, guys");

--------------------------------------------------------------------------------  原型:extern void line(int left, int top, int right, int bottom, int mode);

                        用法:#i nclude <system.h>

                        功能:在屏幕上畫直線

                        說明:(lefttop)和(rightbottom)指定直線的兩個端點座標。mode決定劃線的模式。

                        超出屏幕的線將被裁端。

                        mode值的含義:

                        mode=0:清除方式

                        =1:正常方式

                        =2:取反方式

                        舉例:

                        // line.c

                        i nclude <system.h>

                        main()

                        {

                        clrscr();

                        move(10,10);  // hide cursor

                        block(20,10,100,40,1);

                        line(1,1,111,47,1);  // from top left to bottom right

                        line(1,47,111,1,0);  // from bottom left to top right

                        line(112/2,1,112/2,47,2); // line vertically at the middle of the LCD

--------------------------------------------------------------------------------  原型:extern int kbhit(void);

                        用法:#i nclude <stdio.h>

                        功能:檢測按鍵

                        說明:檢測鍵盤是否有鍵按下。

                        如果有鍵按下,則返回對應鍵值;否則返回零。

                        kbhit不等待鍵盤按鍵。無論有無按鍵都會立即返回。

                        舉例:

                        // kbhit.c

                        i nclude <stdio.h>

                        main()

                        {

                        int i=0;

                        clrscr();

                        while(!kbhit())

                        {

                        clrscr();

                        printf("%05d",i++);

                        }

                        clrscr();

                        printf("End.");

                        getchar();

                        return 0;

                        }  無鍵按下時,返回零;有鍵按下時,返回的不是鍵值,而是 -1  要取得鍵值,可以在循環裏用 getch() 來接收。

 

原型:extern int getchar(void);

                        用法:#i nclude <ctype.h>

                        功能:讀鍵

                        說明:從鍵盤上讀取一個鍵,並返回該鍵的鍵值

                        getch是到getchar的宏定義

                        舉例:

                        // getchar.c

                        i nclude <stdio.h>

                        main()

                        {

                        int c;

                        clrscr();

                        printf("Press key...");

                        while((c=getchar())!='Q')

                        {

                        clrscr();

                        printf("key: %c/nvalue: %x",c,c);

                        }

                       

                       

 

 

發佈了15 篇原創文章 · 獲贊 6 · 訪問量 12萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章