转载的一些常用的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);

                        }

                       

                       

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值