I hope I'm not posting to the wrong place, if so, please remind me :) I'm making some practice on C programming, so that I can get into the linux world. Here is a simple code
129 char comment[1025]; 130 cgiFormString("comment", comment, 1025); 131 if(strcasestr(comment, "</xmp")!=NULL) { fprintf(cgiOut, "</xmp is not allowed"); return; }
when i compile, there is a warning: gcc -o LeaveMessage LeaveMessage.c cgic.c LeaveMessage.c: In function 'LeaveMessage': LeaveMessage.c:131: warning: comparison between pointer and integer
but i found in http://www.gnu.org/software/libc/manual/html_node/Search-Functions.html#Sear... — Function: char * strcasestr (const char *haystack, const char *needle)
So i don't know why i got this warning, what's the correct way to deal with it?
thanks!
On Mon, Jul 14, 2008 at 06:16:06AM +0800, Star Liu wrote:
I hope I'm not posting to the wrong place, if so, please remind me :) I'm making some practice on C programming, so that I can get into the linux world.
Well it seems you're programming a CGI application, so I think this list isn't the best place to ask.
131 if(strcasestr(comment, "</xmp")!=NULL)
..
LeaveMessage.c:131: warning: comparison between pointer and integer
..
So i don't know why i got this warning,
The error says that something is wrong in the comparison. You're comparing a function return value with NULL.
Either the compiler believes that strcasestr() returns integer, or it believes that NULL is defined as integer.
The latter is not so likely because NULL is usually defined as (void *) which is a pointer type, or it is not defined at all. If it was not defined at all, you would get a different error message.
So, the compiler says strcasestr() returns integer. That is the fallback if the compiler has not seen a prototype (or declaration) for a function before it is called.
what's the correct way to deal with it?
I think you may be missing
#include <strings.h>
where strcasecmp() is declared.
//Peter
On Mon, Jul 14, 2008 at 5:46 PM, Peter Stuge peter@stuge.se wrote:
On Mon, Jul 14, 2008 at 06:16:06AM +0800, Star Liu wrote:
I hope I'm not posting to the wrong place, if so, please remind me :) I'm making some practice on C programming, so that I can get into the linux world.
Well it seems you're programming a CGI application, so I think this list isn't the best place to ask.
131 if(strcasestr(comment, "</xmp")!=NULL)
..
LeaveMessage.c:131: warning: comparison between pointer and integer
..
So i don't know why i got this warning,
The error says that something is wrong in the comparison. You're comparing a function return value with NULL.
Either the compiler believes that strcasestr() returns integer, or it believes that NULL is defined as integer.
The latter is not so likely because NULL is usually defined as (void *) which is a pointer type, or it is not defined at all. If it was not defined at all, you would get a different error message.
So, the compiler says strcasestr() returns integer. That is the fallback if the compiler has not seen a prototype (or declaration) for a function before it is called.
what's the correct way to deal with it?
I think you may be missing
#include <strings.h>
where strcasecmp() is declared.
//Peter
thank you, i think there is something wrong with the gcc or strcasestr, but it doesn't matter, i can manually convert it by (char*)((long)strcasestr(a,b))
thank you, i think there is something wrong with the gcc or strcasestr, but it doesn't matter, i can manually convert it by (char*)((long)strcasestr(a,b))
I doubt it. I expect rather you need to do what the manpage for strcasestr recommends and do:
#define _GNU_SOURCE
#include <string.h>
Eric
On Tue, Jul 15, 2008 at 1:06 AM, Eric W. Biederman ebiederm@xmission.com wrote:
I expect rather you need to do what the manpage for strcasestr recommends and do:
#define _GNU_SOURCE #include <string.h>
thank you! you are right, i need the #define _GNU_SOURCE for the strcasestr to compile correctly ! it works now!
Eric