Tag Archives: c

C++动态声明字符串二维数组 int rows=10; int cols=20; WCHAR** titleW = new WCHAR*[rows]; for (int i = 0; i < rows; i++) { titleW[i] = new WCHAR[cols]; } C语言是同样的道理,把new修改为malloc MFC中有CStringArray可用,不过注意,函数返回类型是CStringArray时,必须是返回引用。因为没有拷贝构造函数。

Posted on by tunpishuang | Leave a comment

unsigned int 无限循环问题 今天写了一段如下代码: UINT pos = qb.getArticleCount(); while(pos >= 0) { //…. } 运行的时候发现循环无法结束。调试观察pos尽然是负数。最后恍然大悟,unsigned int的是没有负数的。具体参见我以前写的“补码”一文。

Posted on by tunpishuang | Leave a comment

(c语言)webqq登录

http://tunps.com/lab/c/ConsoleQ.c 代码太多,直接传文件。 用libcurl做http request。 用yajl解析json。 哥将md5算法的javascript实现转为了C语言。转换中发现了一些有趣的东西:>>>(无符号的右移运算符,JS特有,C没有这个运算符,但是C可以通过>>的逻辑右移来实现此运算) WebQQ的登录过程分一下几个步骤,网上已经有详细的讲解,我就不详讲了。 取得验证码check,如果是以!开头的四位字符就无需输入验证码,当然console下面无法显示验证码。 本地md5_3加密完之后login。 cookie中取得ptwebqq之后以json格式login2发送数据。 login2返回json格式的vfwebqq和psessionid。保存起来。 登录后的每次操作(包括重新登录)都需要vfwebqq和psessionid作为token发送。 后续的获取好友列表,接受、发送消息没做。都是用json做交互。哥发现了yajl一处不好用的地方[1,2]就没有继续写下去了。暂时到这里吧。

Tagged | Leave a comment

C字符串转数组,类似于php的explode()

/************************************************************************/ /* 字符串转数组,类似于php的explode(),通过参数指定分隔符号,写得很烂,将就用着*/ /* http://tunps.com */ /************************************************************************/ #include <stdio.h> #include <windows.h> #define N 10 #define M 10 void explode(char *delimiter,int delimiterSize,char *strIn,int strInSize,char** strOut) { int i,j,k=0,m=0,n=0; int isDelimiter[1000]={0}; for(i=0;i<strInSize;i++) { for(j=0;j<delimiterSize;j++) { if(strIn[i] == delimiter[j]) { isDelimiter[i] = 1; … Continue reading

Tagged | Leave a comment

传递多个参数给_beginthread

/*******Test Return Value of Struct *******/ #include <stdio.h> #include <process.h> typedef struct ST{ int num; char* buf; }thestruct; void Addem(thestruct* ); int main() { thestruct st; st.num = 6000; _beginthread((void(*)(void*))Addem,0,(void*)&st); getchar(); // freeze program so you can see output } … Continue reading

Tagged , | Leave a comment

yajl_tree_get return 0 when path node name is the same http://stackoverflow.com/questions/8368520/yajl-tree-get-return-0-when-path-node-name-is-the-same https://github.com/lloyd/yajl/issues/63 问了,没人鸟我,不给力啊。

Posted on by tunpishuang | Leave a comment

补码

最近搞webqq的研究,因为前台密码md5加密有太多了位运算(bit-wise operation),在将js代码转为c代码的过程中发现了一些问题。 c语言里面的位运算有与(&)或(|)非(~)异或(^)左移(<<)右移(>>)。 在32位windows xp,vc2005环境下,int和long都是4位(sizeof(int)==4)。所以我初步判断这样的环境下int和long没有区别。 int分为有符号(signed)和无符号(unsigned)。 当int为有符号时(默认)表示的范围是0×00000000(0)到0x7FFFFFFFF(2147483647)到0×800000000(-2147483648)到0xFFFFFFFF(-1) 当int为无符号时(默认)表示的范围是0×00000000(0)到0x7FFFFFFFF(2147483647)到0×800000000(2147483648)到0xFFFFFFFF(4294967295) 同理2个Bytes的short型数据类型是这样的: signed short:0×0000(0)到0x7FFF(32767)到0×8000(-32768)到0xFFFF(-1) unsigned short:0×0000(0)到0x7FFF(32767)到0×8000(32768)到0xFFFF(65535) 一个关于2进制在计算机中运算的形象例子: 11111 111 (进位) 0000 1111 (15) + 1111 1011 (-5) ================== 0000 1010 (10) 计算机系统中为啥非要使用补码呢?这个问题哥在上大学上汇编课的时候老师没有讲过,只是给你将转码的公式,你记住就有分了。其实大家都忘了补码存在的意义:二补数系统的最大优点是可以在加法或减法处理中,不需因为数字的正负而使用不同的计算方式。只要一种加法电路就可以处理各种有号数加法,而且减法可以用一个数加上另一个数的二补数来表示,因此只要有加法电路及二补数电路即可完成各种有号数加法及减法,在电路设计上相当方便。 总之优点降低电路设计的复杂度。 more info : http://zh.wikipedia.org/wiki/二補數

Tagged | 1 Comment

libcurl 无法解析的外部符号

仔细检查一下几点,防止“无法解析的外部符号”链接问题的出现。 确保curllib项目的运行时库和引用curllib.lib程序的运行时库(c/c++ ->code generation)保持一致(比如都是/MDd)。 确保curllib项目和引用curllib.lib项目的程序的字符集保持一致(比如都是:使用多字节字符集)。 确保curllib项目在没有LDAP支持的情况下在preprocessor definition中加入:CURL_DISABLE_LDAP(/D)。 编译curllib静态库时,请在preprocessor definition中加入:CURL_STATICLIB

Tagged , | Leave a comment

VC编译curl 7.19.0

打开curl-7.19.0\vc6curl.dsw F7编译。报错: D:\win32dev\curl-7.19.0\lib\ldap.c(49) : fatal error C1189: #error :  Your Platform SDK is NOT sufficient for LDAP support! Update your Platform SDK, or disable LDAP LDAP support! 如果不需要编译出来的libcurl.lib支持LDAP,在VC菜单Project->Settings->c/c++->Preprocessor definitions加上:CURL_DISABLE_LDAP 在vc2005下一切正常。无需添加这个CURL_DISABLE_LDAP。

Tagged , | Leave a comment

WSAETIMEDOUT&WSAECONNREFUSED

WSAETIMEDOUT 10060   Connection timed out. A connection attempt failed because the connected party did not properly respond after a period of time, or the established connection failed because the connected host has failed to respond. WSAECONNREFUSED 10061   Connection … Continue reading

Tagged , , | Leave a comment