Re: C Programming warning
Hi
2008/7/14 Star Liu <minxinjianxin@gmail.com>:
> 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#Search-Functions
> — 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?
I think, it means, you did not add the line "#include <string.h>" in
your .c file.
So function strcasestr() is not defined while you compile this file.
And the compiler assume strcasestr() returns an intenger. It is the
right behaviour according to the ANSI C/ISO C89/ISO C99.
I recommanded you add the line "#include <string.h>" in your .c file.
And remove the type cast. It should works fine.
--
Regards,
GONG Jie (龚颉)
Email: neo@mamiyami.com
Reply to: