[問題] sscanf 16進位

看板C_and_CPP作者 (科兒)時間10年前 (2014/04/18 18:57), 編輯推噓0(001)
留言1則, 1人參與, 最新討論串1/1
開發平台(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
long要加l short要加h
04/18 21:10, 1F
文章代碼(AID): #1JKGKGui (C_and_CPP)