#Linux中的GCC编程# 一些有用的小功能C代码

1、输入并识别键盘上的上下左右

#include <stdio.h>
#include <string.h>
#include <stdlib.h>

//分配内存的大小
#define     SIZE    10
//定义按键们的宏
#define     ESC     "\033"
#define     UP      "\033[A"
#define     DOWN    "\033[B"
#define     LEFT    "\033[D"
#define     RIGHT   "\033[C"

int main()
{
    char *get = (char*)malloc(SIZE);

    for ( ; ; ) 
    {   
        fgets(get, SIZE, stdin);
        /*    用fgets()函数从stdin中读取字符串时,会自动在字符串末尾追加"\n",这里将末尾字符改为"\0"    */
        get[strlen(get) - 1] = '\0';

        if (!strcmp(get, ESC))
            printf("This is \"ESC\" button!\n");
        if (!strcmp(get, UP))
            printf("This is \"UP\" button!\n");
        if (!strcmp(get, DOWN))
            printf("This is \"DOWN\" button!\n");
        if (!strcmp(get, LEFT))
            printf("This is \"LEFT\" button!\n");
        if (!strcmp(get, RIGHT))
            printf("This is \"RIGHT\" button!\n");
    }   

    return 0;
}

运行结果:每次按一个方向键,需要再敲一下回车(用于刷新缓存)。

kshine@kshine-virtual-machine:~/桌面/GCC$ gcc udlr1.c  -o main -Wall
kshine@kshine-virtual-machine:~/桌面/GCC$ ./main
^[[A
This is "UP" button!
^[[D
This is "LEFT" button!
^[[B
This is "DOWN" button!
^[[C
This is "RIGHT" button!

2、针对上述测试代码,出现的问题,我们可以引入system("stty -icanon"); 如下代码所示

#include <stdio.h>
#include <stdlib.h>
int main()
{
        char ch;
        system("stty -icanon");//关闭缓冲区,输入字符无需回车直接接受
        ch = getchar();
        if(ch == 'a')
                printf("OK\n");
        return 0;
}

3、printf(),高亮显示

#include"stdio.h"
int main()
{
	printf("\033[40;39m  底色40黑色,字色39无无  \033[0m\n");//\033[;m  ……  \033[0m
	printf("\033[41;38m  底色41深红,字色38无无  \033[0m\n");//\033[;m  ……  \033[0m
	printf("\033[42;37m  底色42绿色,字色37白色  \033[0m\n");//\033[;m  ……  \033[0m
	printf("\033[43;36m  底色43黄色,字色36深绿  \033[0m\n");//\033[;m  ……  \033[0m
	printf("\033[44;35m  底色44蓝色,字色35紫色  \033[0m\n");//\033[;m  ……  \033[0m
	printf("\033[45;34m  底色45紫色,字色34蓝色  \033[0m\n");//\033[;m  ……  \033[0m
	printf("\033[46;33m  底色46深绿,字色33黄色  \033[0m\n");//\033[;m  ……  \033[0m
	printf("\033[47;32m  底色47白色,字色32绿色  \033[0m\n");//\033[;m  ……  \033[0m
	printf("\033[48;31m  底色48无无,字色31红色  \033[0m\n");//\033[;m  ……  \033[0m
	printf("\033[49;30m  底色49无无,字色30黑色  \033[0m\n");//\033[;m  ……  \033[0m
	return 0;
}

4、实现strcmp+只读形参

5、实现strcpy+断言函数

6、实现strlen

7、指针常量和常量指针

8、指针与自加 符号的优先级

9、特殊函数

9.1 产生随机数字

9.2 产生随机验证码,并输入验证

9.3 输出系统当前时间

10、函数指针以及函数指针数组的定义与使用

10.1 函数指针的定义与使用

10.2 函数指针数组的定义与使用

11、整型数组的冒泡排序

 

 

 

 

 

 

 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
linux环境下的snmp测试脚本, Installing SNMPv2C Agent Conformance Test Package 2008/04/08 IPv6 Promotion Council Terminology =========== Tester Node (TN) A tester node for the conformance tests. Node Under Test (NUT) A testee node for the conformance tests. Network Under Test The network where the conformance tests are executed. Tester Interface The network interface of TN hooked up to the Network Under Test. Interface Under Test The network interface of NUT hooked up to the Network Under Test. Prerequisites ============= Prerequisites for TN: - The package supports FreeBSD 6.0-RELEASE or higher version. - The package can also coexist with FreeBSD version of KAME. Installing the package onto TN ============================== 0. Before Starting (A) You need to install following softwares. - Perl (Required version : 5.8.7 or higher) - Net-SNMP (Required version : 5.3.1 or higher) *** You can download it from the following URL: http://net-snmp.sourceforge.net/ - v6eval (Required version : 3.0.11 or higher) Please refer to 00README.v6eval in "v6eval" for more information. *** You can download it from the following URL: http://www.tahi.org/release/ - koi (Required version : 1.1.1 or higher) Please refer to README file in "koi" package for more information. *** You can download it from the following URL: http://www.tahi.org/release/ 1. Extracting ct package % tar zxvf ct-snmpv2c-ag-X.X.tar.gz 2. Copying ct package Copy ct directory to any directory you like. % cp -pR $ORGDIR/ct-snmpv2c-ag-X.X $SOMEWHERE/ct-snmpv2c-ag-X.X % chmod -R +w $SOMEWHERE/ct-snmpv2c-ag-X.X 4. Setup ct environment % (enable TN's ipv6 capibility) % cd $SOMEWHERE/ct-snmpv2c-ag-X.X % edit config.txt % make test [End of INSTALL]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值