开发者

can you declare data in a char** using hex?

开发者 https://www.devze.com 2022-12-31 12:52 出处:网络
lets say I have this char *something[] = { \"/bi\", \"-c\", \"5\", NULL, NULL }; but I want to declare it in hex, how 开发者_Go百科would I do this; compiler keeps erroring out on me:

lets say I have this

char *something[] = { 
    "/bi", 
    "-c", 
    "5", 
    NULL, 
    NULL 
};

but I want to declare it in hex, how 开发者_Go百科would I do this; compiler keeps erroring out on me:

char *something[] = { 
    {0x2f,0x62,0x69},
    {0x2d,0x63},
    {0x35},
    {0x00}, 
    {0x00}
};

to add something else to this, is 0x00 ALWAYS null? does 0x00 always translate to NULL on systems where NULL is -1 for example?


You can use hexadecimal escape sequences within a string literal. For example:

char *something[] = { 
    "\x2f\x62\x69",
    "\x2d\x63"
}; 


To answer your question about NULL and the null pointer: the macro NULL is always 0. The compiler then converts that to an appropriate null pointer. The comp.lang.c FAQ has an entire section explaining this more thoroughly.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号