char a[128] = {0};
方法1:知道自己要写到哪位,直接替换字符值:
a[0]=0x2;
a[1]=0x3;
方法2:转义写入
snprintf(a,sizeof(a), “\002 \003”);
或者
snprintf(a,sizeof(a), “%c %c”, 0x2,0x3);
例子:
环境: ubuntu
ctrl alt t进入命令行界面
vi test.c
#include<stdio.h>
#include<string.h>
int main(){
char a[128] = {0};
char b[128] = {0};
snprintf(a, sizeof(a),"\002 passersby! \003");//snprintf(a, sizeof(a),"%c passersby! %c", 0x2,0x3);
snprintf(b, sizeof(b)," a silly dog ");
b[0]=0x2;
b[strlen(b)-1]=0x3;
printf("%s\n%s\n", a, b);
return 0;
}
编译查看结果
:wq #保存test.c文件并退出vi
gcc test.c -o a
./a