use htonl convert a int number, and memcpy to a char*, but nothing

一笑奈何 提交于 2019-12-11 13:55:28

问题


code like this:

int totalLen = 50;

int usTest = htons(totalLen);

char* strBuf = new char[totalLen ];

memcpy(strBuf,&usTest,sizeof(int));

after this,there is nothing in strBuf, why?

but if I put a big number, like 100000001, it will be OK?

what's the problem?

来源:https://stackoverflow.com/questions/19818704/use-htonl-convert-a-int-number-and-memcpy-to-a-char-but-nothing

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!