转载的一些常用的C函数,还有些用途

来源:互联网 发布:java开源周报管理系统 编辑:程序博客网 时间:2024/06/05 02:35

 

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);

                        }

                       

                       

 

 

原创粉丝点击