[問題] sscanf 16進位
開發平台(Platform): (Ex: VC++, GCC, Linux, ...)
All
額外使用到的函數庫(Library Used): (Ex: OpenGL, ...)
問題(Question):
餵入的資料(Input):
預期的正確結果(Expected Output):
錯誤結果(Wrong Output):
程式碼(Code):(請善用置底文網頁, 記得排版)
#include <stdio.h>
int main ()
{
char sentence []="200a\n 1234\n";
char str [20];
int i;
unsigned long addr;
unsigned short port;
sscanf (sentence,"%x\n %d\n",&addr,&port);
printf ("%x -> %d\n",addr, port);
system("pause");
return 0;
}
預期會是
200a -> 1234
但是結果卻是
0->1234
有人知道為什麼嗎?
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 220.135.250.104
※ 文章網址: http://www.ptt.cc/bbs/C_and_CPP/M.1397818640.A.E2C.html
→
04/18 21:10, , 1F
04/18 21:10, 1F