Home > Archive > Unix Programming > January 2008 > how to use strcasestr
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
how to use strcasestr
|
|
| nodrogbrown 2008-01-28, 4:33 am |
| hi
i am a beginner in c and uses cygwin on winXP
in my c code i am trying to use strcasestr() to compare a string with
another..the problem is that gcc doesn't find this fn in its std
libraries (string.h..) ..i was advised to compile with _GNU_SOURCE
defined ..but i don't know how to do this..i did a search of my
cygwin installation for any .c ,.h files for strcasestr but found
none ..can someone tell me how to compile ?
TIA
gordon
| |
| fred.l.kleinschmidt@boeing.com 2008-01-28, 7:24 pm |
| On Jan 27, 10:08=A0pm, nodrogbrown <nodrogbr...@gmail.com> wrote:
> hi
> i am a beginner in c and uses cygwin on winXP
> in my c code i am trying to use strcasestr() to compare a string with
> another..the problem is that gcc doesn't find this fn in its std
> libraries (string.h..) ..i was advised to compile with =A0_GNU_SOURCE
> defined =A0..but i don't know how to do this..i did a search of my
> cygwin installation for any .c ,.h files for strcasestr but found
> none ..can someone tell me how to compile ?
> TIA
> gordon
#define _GNU_SOURCE
#include <string.h>
This assumes that your compiler and implementation have that
particular
extension (strcasestr is non-standard)
--
Fred Kleinschmidt
| |
| ~Glynne 2008-01-29, 4:38 am |
| On Jan 27, 11:08 pm, nodrogbrown <nodrogbr...@gmail.com> wrote:
> hi
> i am a beginner in c and uses cygwin on winXP
> in my c code i am trying to use strcasestr() to compare a string with
> another..the problem is that gcc doesn't find this fn in its std
> libraries (string.h..) ..i was advised to compile with _GNU_SOURCE
> defined ..but i don't know how to do this..i did a search of my
> cygwin installation for any .c ,.h files for strcasestr but found
> none ..can someone tell me how to compile ?
> TIA
> gordon
/* GCC often has strcasestr(); if not, you can use the following */
#include <ctype.h>
/* borrowed these definitions from apache */
#define ap_tolower(c) (tolower(((unsigned char)(c))))
#define ap_toupper(c) (toupper(((unsigned char)(c))))
static inline
char *strcasestr( char *h, char *n )
{ /* h="haystack", n="needle" */
char *a=h, *e=n;
if( !h || !*h || !n || !*n ) { return 0; }
while( *a && *e ) {
if( ap_toupper(*a)!=ap_toupper(*e) ) {
++h; a=h; e=n;
}
else {
++a; ++e;
}
}
return *e ? 0 : h;
}
~Glynne
| |
| nodrogbrown 2008-01-29, 4:38 am |
|
>
> /* GCC often has strcasestr(); if not, you can use the following */
Glynne
many thanx!!
gordon
|
|
|
|
|