2014-09-25 72 views
0

我想查看這是否實際上可以在C代碼中使用。如何在無符號數組中組合字符和數字char

unsigned char message[] = {0x00,0x00,"Hello world"}; 

有一些固件,我想迫使採取比爲0x00其他人物在同一陣列英寸它有:

unsigned char message[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
          0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
          0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
          0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; 

已經寫在裏面。我希望它採取其他字符,因爲這兩個是可能的:

unsigned char message[] = "Hello world"; 

unsigned char message2[] = {0x00,0x00,0x00}; 

我有一個存儲從一個UART的信件,我想在編譯器告訴你

unsigned char message2[] = {0x00,0x00,0x00}; 
+0

答:你不能。 – haccks 2014-09-25 17:09:12

+0

你想做什麼?你有很多這樣的消息嗎? – 2014-09-25 17:12:47

+0

以及爲什麼你認爲「Hello World」是一個字符或整數? – 2014-09-25 17:16:24

回答

1

結合的緩衝區,你不能以你試圖做到的方式去做你想做的事。

注意,你可以使用:需要

unsigned char message[] = "\x00\x00Hello world"; 

但相當小心,因爲:

unsigned char message[] = "\x00\x00Byebye world"; 

具有包含\xB\013第二字節和第三個字節是y。十六進制轉義停止在不是十六進制數字的第一個字符處(因此"\x00Babaganoush"在十六進制轉義中有六位數;並且有很多拼寫方法'Babaganoush')。

相關問題