[問題] sscanf 16進位

作者: enjoy222 (科兒)   2014-04-18 18:57:17
開發平台(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
有人知道為什麼嗎?
作者: x000032001 (版廢了該走了)   2014-04-18 21:10:00
long要加l short要加h

Links booklink

Contact Us: admin [ a t ] ucptt.com