曲径通幽论坛

标题: gtk_combo_box_get_active_text 与 '\0' 不是 NULL ? [打印本页]

作者: beyes    时间: 2010-4-20 02:59
标题: gtk_combo_box_get_active_text 与 '\\0' 不是 NULL ?
调试 GTK 的一个函数  gtk_combo_box_get_active_text ()

其中说明文档上说是,如果没有选择任何东西,返回 NULL,但实际实验的结果是 '\0' ,'\0' 算是一个字符,而不是 NULL。

像以下程序中(组合框操作):
[Plain Text] 纯文本查看 复制代码
url_in_combobox = gtk_combo_box_get_active_text(user_data);    
        if (url_in_combobox == NULL) {
            stream = fopen (filename, "w");
            fclose (stream);   
        } else {
            strcat (url_buf, filename);
            strcat (url_buf, html);
            strcat (url_buf, url_in_combobox);
            system (url_buf);
            g_free (url_in_combobox);
         }

上面,当组合框里未包含任何字符时,甚至鼠标指针不在组合框中,得到的 url_in_combobox 不是 NULL,因为程序总是跑在 eles {} 里边去。由此可见,返回值并不是 NULL 。

如果修改判断语句为 url_in_combobox[0] == '\0' 就可以看到 if 为真。

这说明了, gtk_combo_box_get_active_text() 返回的是 '\0' 空字符,而不是 NULL 指针,这个指针还是又所指的。




欢迎光临 曲径通幽论坛 (http://www.groad.net/bbs/) Powered by Discuz! X3.2