我们这里举个例子,以字符串“你好啊”为例,分析每个汉字的GBK码:
#include "sys.h"
#include "delay.h"
#include "usart.h"
#include "led.h"
#include "string.h"
char arrBuf_1[3] = {'f','a','t'};
char arrBuf_2[4] = {'f','a','t','\0'};
char strBuf_1[] = "fat";
const char* strBuf_2 = "你好啊";
int main(void)
{
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);//设置系统中断优先级分组2
delay_init(168); //初始化延时函数
uart_init(115200);//初始化串口波特率为115200
if(!strcmp(arrBuf_1,strBuf_1))
{printf("arrBuf_1 与 strBuf_1 相等\r\n");}
else if(!strcmp(arrBuf_2,strBuf_1))
{printf("arrBuf_2 与 strBuf_1 相等\r\n");}
else
{printf("数组与字符串均不相等\r\n");}
printf("arrBuf_1的地址为:0x%x\r\n",arrBuf_1);
printf("arrBuf_2的地址为:0x%x\r\n",arrBuf_2);
printf("strBuf_1的地址为:0x%x\r\n",strBuf_1);
printf("arrBuf_1中'f'字符常量的地址为:0x%x\r\n",*arrBuf_1);
printf("arrBuf_2中'f'字符常量的地址为:0x%x\r\n",*arrBuf_2);
printf("strBuf_1中'f'字符常量的地址为:0x%x\r\n",*strBuf_1);
printf("strBuf_2汉字常量‘你’的GBK码高位码为:0x%x\r\n",*strBuf_2);
printf("strBuf_2汉字常量‘你’的GBK码低位码为:0x%x\r\n",*(strBuf_2+1));
printf("strBuf_2汉字常量‘好’的GBK码高位码为:0x%x\r\n",*(strBuf_2+2));
printf("strBuf_2汉字常量‘好’的GBK码低位码为:0x%x\r\n",*(strBuf_2+3));
printf("strBuf_2汉字常量‘啊’的GBK码高位码为:0x%x\r\n",*(strBuf_2+4));
printf("strBuf_2汉字常量‘啊’的GBK码低位码为:0x%x\r\n",*(strBuf_2+5));
while(1);
return 0;
}
|