[问题] 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