... <看更多>
「unsigned char」的推薦目錄:
- 關於unsigned char 在 [問題] printf 和unsigned char* - 看板C_and_CPP - 批踢踢實業坊 的評價
- 關於unsigned char 在 What is an unsigned char? - Stack Overflow 的評價
- 關於unsigned char 在 unsigned char* to base64 format with openssl - gists · GitHub 的評價
- 關於unsigned char 在 23. Unsigned char Data Type - YouTube 的評價
- 關於unsigned char 在 char_traits< unsigned char > Struct Template Reference 的評價
- 關於unsigned char 在 Char and unsigned char - Software Engineering Stack ... 的評價
unsigned char 在 unsigned char* to base64 format with openssl - gists · GitHub 的推薦與評價
unsigned char * to base64 format with openssl. GitHub Gist: instantly share code, notes, and snippets. ... <看更多>
unsigned char 在 char_traits< unsigned char > Struct Template Reference 的推薦與評價
Static Public Member Functions. static size_t, length (const unsigned char *str). static void, assign (unsigned char &left, const unsigned char &right). ... <看更多>
unsigned char 在 Char and unsigned char - Software Engineering Stack ... 的推薦與評價
Where is unsigned char used in C ( please tell about some real-world examples )? Why would we need both char and unsigned char? signed or unsigned are ... ... <看更多>
unsigned char 在 [問題] printf 和unsigned char* - 看板C_and_CPP - 批踢踢實業坊 的推薦與評價
開發平台(Platform): (Ex: VC++, GCC, Linux, ...)
GCC Linux SUSE
問題(Question):
最近在寫C,碰到大量的unsigned char*,然後又得認命的去看內容兼找錯,
只好利用printf來把內容顯示出來看,不過在一連串意外之後,
我對printf越來越陌生了 Q口Q
先直接看下面的測試程式:
int int01 = 100;
unsigned char *str;
unsigned char *tmp;
str = (unsigned char *)malloc(1);
tmp = (unsigned char *)malloc(2);
sprintf(str,"%d",int01); //將int01的數值利用sprintf餵給str
memcpy(tmp,str,1); //利用memcpy把數值copy給tmp
printf("%d\n",*str); //輸出 49 (神奇的49....不知道哪來的)
printf("%u\n",*str); //輸出 49 (unsigned dec和樓上吻合)
printf("%x\n",*tmp); //輸出 31 (16進位和樓上吻合)
printf("%x\n",*(tmp+1) ); //輸出 0 (第二個byte沒有數值 正確)
想請問大大,要怎麼餵數值給unsigned char*?
輸出49真的讓我有點傻眼,為什麼不是100 >"<
再請問大大,如果我要在unsigned char *str 當中餵入100的二進位(0x1100100)
然後用printf() 顯示出100的話,我該怎麼改?
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 60.251.71.22
... <看更多>