当前位置:网站首页>C language improvement article (wchar_t) character type
C language improvement article (wchar_t) character type
2022-07-03 12:01:00 【Ch_ champion】
summary
original C The language is so beautiful ^_^~, Programming ideas inspired by . I have seen similar expressions on many large projects , So today write a Demo, Make a note of , Convenient for later viewing .
IDE:vscode
1、 Source code
#define ARRAY_SIZE(array) (sizeof(array) / sizeof(array[0]))
typedef enum
{
language_SChinese = 0,
language_English,
}LANGUAGE_T;
typedef struct
{
volatile uint8_t value;
volatile LANGUAGE_T language;
}__attribute__((packed)) SysType_ty;
SysType_ty Sys;
typedef struct
{
uint8_t item_icon;
uint8_t item_title;
}MenuList;
/**
* footwear
*/
typedef enum {
S_badminton = 0,
S_baseball,
S_hockey,
S_football,
S_basketball,
S_rugby,
S_volleyball, //6
S_tennis,
S_table_tennis,
S_billiards, //9
S_ping_pong,
S_golf,
S_count,
}footwearTy;
typedef enum {
t_ERROR = 0,
t_BADMINTON,
t_BASEBALL,
t_HOCKEY,
t_FOOTBALL,
t_BASKETBALL,
t_RUGBY,
t_VOLLEYBALL, //6
t_TENNIS,
t_TABLE_TENNIS,
t_BILLIARDS, //9
t_PING_PONG,
t_GOLF,
t_count,
}String_id;
static MenuList const item_lists[] = {
{S_volleyball, t_VOLLEYBALL},
{S_rugby, t_RUGBY},
{S_tennis, t_TENNIS},
{S_billiards, t_BILLIARDS},
{S_hockey, t_HOCKEY},
};
/**
* show_footwear
*/
uint16_t const init_footwear_index_Lists[S_count] = {
[S_badminton ] = 0,
[S_baseball ] = 2,
[S_hockey ] = 7,
[S_football ] = 0,
[S_basketball ] = 1,
[S_rugby ] = 3,
[S_volleyball ] = 0,
[S_tennis ] = 5,
[S_table_tennis ] = 6,
[S_billiards ] = 8,
[S_ping_pong ] = 4,
[S_golf ] = 9,
};
static wchar_t * const footwear_title_lists_en[t_count] = {
[t_ERROR ] = L"error",
[t_BADMINTON ] = L"badminton",
[t_BASEBALL ] = L"baseball",
[t_HOCKEY ] = L"hockey",
[t_FOOTBALL ] = L"football",
[t_BASKETBALL ] = L"basketball",
[t_RUGBY ] = L"rugby",
[t_VOLLEYBALL ] = L"volleyball",
[t_TENNIS ] = L"tennis",
[t_TABLE_TENNIS ] = L"table_tennis",
[t_BILLIARDS ] = L"billiards",
[t_PING_PONG ] = L"ping_pong",
[t_GOLF ] = L"golf",
};
static wchar_t * const footwear_title_lists_cn[t_count] = {
[t_ERROR ] = L" error ",
[t_BADMINTON ] = L" badminton ",
[t_BASEBALL ] = L" Baseball ",
[t_HOCKEY ] = L" Hockey ",
[t_FOOTBALL ] = L" football ",
[t_BASKETBALL ] = L" Basketball ",
[t_RUGBY ] = L" rugby ",
[t_VOLLEYBALL ] = L" Volleyball ",
[t_TENNIS ] = L" Tennis ",
[t_TABLE_TENNIS ] = L" Table tennis ",
[t_BILLIARDS ] = L" Billiards ",
[t_PING_PONG ] = L" Table Tennis ",
[t_GOLF ] = L" Golf ",
};
static wchar_t * const * string_list = footwear_title_lists_en;
wchar_t * string_get(String_id id)
{
return (wchar_t *) (string_list[id]);
}
LANGUAGE_T language_get(void)
{
return Sys.language;
}
void init_language(void)
{
Sys.language = language_English;
switch (Sys.language)
{
case language_SChinese:
/* code */
string_list = footwear_title_lists_cn;
break;
case language_English:
/* code */
string_list = footwear_title_lists_en;
break;
default:
Sys.language = language_English;
init_language();
break;
}
}
int main()
{
init_language();
printf("str:%s\r\n", string_get((String_id)item_lists[1].item_title));
printf("str:%s\r\n", footwear_title_lists_cn[item_lists[1].item_title]);
for (int i = 0; i < ARRAY_SIZE(item_lists); i++)
{
printf("i:%d, item_icon: %d, item_title: %d\r\n", i, item_lists[i].item_icon, item_lists[i].item_title);
printf("i:%d, show_icon: %d, show_title: %s\r\n", i, init_footwear_index_Lists[item_lists[i].item_icon], string_get((String_id)item_lists[i].item_title));
}
system("pause");
return 0;
}2、 Running results

边栏推荐
- PHP get the file list and folder list under the folder
- R language uses grid of gridextra package The array function combines multiple visual images of the lattice package horizontally, and the ncol parameter defines the number of columns of the combined g
- VS2015的下载地址和安装教程
- 小鹏 P7 撞护栏安全气囊未弹出,官方回应称撞击力度未达到弹出要求
- ArcGIS应用(二十一)Arcmap删除图层指定要素的方法
- Niuniu's team competition
- ArcGIS application (XXI) ArcMap method of deleting layer specified features
- Test classification in openstack
- Uniapp implementation Click to load more
- 【mysql官方文档】死锁
猜你喜欢

Vulnhub narak

Unity3d learning notes 5 - create sub mesh

ArcGIS应用(二十一)Arcmap删除图层指定要素的方法

为什么我的mysql容器启动不了呢

vulnhub之GeminiInc

Colleagues wrote a responsibility chain model, with countless bugs

小鹏 P7 撞护栏安全气囊未弹出,官方回应称撞击力度未达到弹出要求

Is BigDecimal safe to calculate the amount? Look at these five pits~~

Yintai department store ignites the city's "night economy"

Solve msvcp120d DLL and msvcr120d DLL missing
随机推荐
MCDF Experiment 1
牛牛的组队竞赛
previous permutation lintcode51
Vulnhub's presidential
(database authorization - redis) summary of unauthorized access vulnerabilities in redis
Wrong arrangement (lottery, email)
SystemVerilog -- OOP -- copy of object
OPenGL 基本知识(根据自己理解整理)
rxjs Observable filter Operator 的实现原理介绍
并发编程-单例
Download address and installation tutorial of vs2015
Basic knowledge of OpenGL (sort it out according to your own understanding)
typeScript
CGroup introduction
Simple factory and factory method mode
vulnhub之Ripper
MySQL searches and sorts out common methods according to time
Qt OpenGL 旋转、平移、缩放
How to convert a numeric string to an integer
网络通讯之Socket-Tcp(一)