Hi
Im doing a C code using GCC.
I tried to compare (case Incensitive) two strings.. but it seems dont
"know" strcmpi.. Im using 2 headers string.h and stdio.h
How can I do this?
Ex:
#include <stdio.h>
#include <string.h>
int main (void)
{
char * str = "Case";
char * str1 = "cAsE";
if (strcmpi(str,str1)==0)
printf("Same\n");
else
printf("Sorry\n");
}
Tks
Eduardo Elias Camponez 14 29391
"Eduardo Elias Camponez" <ca******@yahoo.com.br> wrote in message
news:a3**************************@posting.google.c om... Hi Im doing a C code using GCC. I tried to compare (case Incensitive) two strings.. but it seems dont "know" strcmpi.. Im using 2 headers string.h and stdio.h How can I do this?
Ex: #include <stdio.h> #include <string.h>
int main (void) { char * str = "Case"; char * str1 = "cAsE";
if (strcmpi(str,str1)==0) printf("Same\n"); else printf("Sorry\n"); }
Tks
Eduardo Elias Camponez
I believe strcmpi is an implementation-defined header. Try looking for it
in the man pages. Under VC++ it is called using _strcmpi() so may be
similar for your case.
Allan
Eduardo Elias Camponez wrote in
<a3**************************@posting.google.com >: Hi Im doing a C code using GCC. I tried to compare (case Incensitive) two strings.. but it seems dont "know" strcmpi.. Im using 2 headers string.h and stdio.h How can I do this?
you probably have
strcasecmp()
"Eduardo Elias Camponez" <ca******@yahoo.com.br> wrote in message
news:a3**************************@posting.google.c om... Hi Im doing a C code using GCC. I tried to compare (case Incensitive) two strings.. but it seems dont "know" strcmpi.. Im using 2 headers string.h and stdio.h How can I do this?
Ex: #include <stdio.h> #include <string.h>
int main (void) { char * str = "Case"; char * str1 = "cAsE";
if (strcmpi(str,str1)==0) printf("Same\n"); else printf("Sorry\n"); }
Tks
Eduardo Elias Camponez
Just provide your own version of ``strcmpi'' .. although I think you might
want to rename it, since str* is reserved by the implementation if I am not
mistaken.
----------------------------
#include <ctype.h>
int stricmp(char *s1, char *s2)
{
for (; *s1 && *s2 && (toupper(*s1) == toupper(*s2)); ++s1, ++s2);
return *s1 - *s2;
}
----------------------------
Maybe change its name to cmpistr? to avoid invoking undefined behaviour.
"j" <ja*******@bellsouth.net> wrote: Just provide your own version of ``strcmpi'' .. although I think you might want to rename it, since str* is reserved by the implementation if I am not mistaken.
Yes, it is.
---------------------------- #include <ctype.h>
int stricmp(char *s1, char *s2)
int my_stricmp(const char *s1, const char *s2)
The parameters should be pointers to const char, for consistency with
the strcmp function.
{ for (; *s1 && *s2 && (toupper(*s1) == toupper(*s2)); ++s1, ++s2);
for (; *s1 && *s2 && (toupper((unsigned char)*s1) ==
toupper((unsigned char)*s2)); ++s1, ++s2);
You must convert the 'char' argument to 'unsigned char' to ensure that
there can be no negative values passed to the toupper function. The C
standard requires that the input to toupper() must be in the range of
'unsigned char'.
return *s1 - *s2;
There is no guarantee that the subtraction of two arbitrary 'char's
will be within the range of an int. On a very weird implementation
this could cause overflow problems.
} ----------------------------
--
Simon.
"Allan Bruce" <al*****@TAKEAWAYf2s.com> wrote: "Eduardo Elias Camponez" <ca******@yahoo.com.br> wrote in message news:a3**************************@posting.google. com... Hi Im doing a C code using GCC. I tried to compare (case Incensitive) two strings.. but it seems dont "know" strcmpi.. Im using 2 headers string.h and stdio.h How can I do this?
Ex: #include <stdio.h> #include <string.h>
int main (void) { char * str = "Case"; char * str1 = "cAsE";
if (strcmpi(str,str1)==0) printf("Same\n"); else printf("Sorry\n"); }
Tks
Eduardo Elias Camponez
I believe strcmpi is an implementation-defined header. Try looking for it in the man pages. Under VC++ it is called using _strcmpi() so may be similar for your case. Allan
The OP didn't mention a header called strcmpi.
Neither the strcmpi() nor _strcmpi() functions are standard C.
Irrwahn
--
Great minds run in great circles.
keanu <us****@keanu.be> wrote: Eduardo Elias Camponez wrote in <a3**************************@posting.google.com> :
Hi Im doing a C code using GCC. I tried to compare (case Incensitive) two strings.. but it seems dont "know" strcmpi.. Im using 2 headers string.h and stdio.h How can I do this?
you probably have strcasecmp()
strcasecmp() is not a standard C function.
Irrwahn
--
Great minds run in great circles.
"j" <ja*******@bellsouth.net> wrote: "Eduardo Elias Camponez" <ca******@yahoo.com.br> wrote in message news:a3**************************@posting.google. com... Hi Im doing a C code using GCC. I tried to compare (case Incensitive) two strings.. but it seems dont "know" strcmpi.. Im using 2 headers string.h and stdio.h How can I do this?
Ex: #include <stdio.h> #include <string.h>
int main (void) { char * str = "Case"; char * str1 = "cAsE";
if (strcmpi(str,str1)==0) printf("Same\n"); else printf("Sorry\n"); }
Tks
Eduardo Elias Camponez Just provide your own version of ``strcmpi'' .. although I think you might want to rename it, since str* is reserved by the implementation if I am not mistaken.
To be exact, ISO/IEC 9899:1999 states:
7.26.11 String handling <string.h>
Function names that begin with str, mem, or wcs and a lowercase
letter may be added to the declarations in the <string.h> header.
A perfectly valid name would be e.g.: strCmpi ---------------------------- #include <ctype.h>
int stricmp(char *s1, char *s2) { for (; *s1 && *s2 && (toupper(*s1) == toupper(*s2)); ++s1, ++s2);
return *s1 - *s2; } ----------------------------
Maybe change its name to cmpistr? to avoid invoking undefined behaviour.
That's another possibility.
Regards
Irrwahn
--
Great minds run in great circles.
"Irrwahn Grausewitz" <ir*****************@freenet.de> wrote in message
news:8s********************************@4ax.com... "Allan Bruce" <al*****@TAKEAWAYf2s.com> wrote:
"Eduardo Elias Camponez" <ca******@yahoo.com.br> wrote in message news:a3**************************@posting.google. com... Hi Im doing a C code using GCC. I tried to compare (case Incensitive) two strings.. but it seems dont "know" strcmpi.. Im using 2 headers string.h and stdio.h How can I do this?
Ex: #include <stdio.h> #include <string.h>
int main (void) { char * str = "Case"; char * str1 = "cAsE";
if (strcmpi(str,str1)==0) printf("Same\n"); else printf("Sorry\n"); }
Tks
Eduardo Elias Camponez
I believe strcmpi is an implementation-defined header. Try looking for
it
oops, I meant function!
in the man pages. Under VC++ it is called using _strcmpi() so may be similar for your case. Allan
The OP didn't mention a header called strcmpi. Neither the strcmpi() nor _strcmpi() functions are standard C.
I know, I was merely trying to indicate a possible area for the OP to look
at ca******@yahoo.com.br (Eduardo Elias Camponez) writes: Hi Im doing a C code using GCC. I tried to compare (case Incensitive) two strings.. but it seems dont "know" strcmpi.. Im using 2 headers string.h and stdio.h How can I do this?
Ex: #include <stdio.h> #include <string.h>
int main (void) { char * str = "Case"; char * str1 = "cAsE";
if (strcmpi(str,str1)==0) printf("Same\n"); else printf("Sorry\n"); }
There is no standard C library function for performing
case-insensitive comparisons against two strings. (OT:) If you
are willing to limit portability to POSIX platforms and systems
which provide the function as an extension, you may use
strcasecmp().
-Micah ca******@yahoo.com.br (Eduardo Elias Camponez) writes: Hi Im doing a C code using GCC. I tried to compare (case Incensitive) two strings.. but it seems dont "know" strcmpi.. Im using 2 headers string.h and stdio.h How can I do this?
Ex: #include <stdio.h> #include <string.h>
int main (void) { char * str = "Case"; char * str1 = "cAsE";
if (strcmpi(str,str1)==0) printf("Same\n"); else printf("Sorry\n"); }
There is no standard C library function for performing
case-insensitive comparisons against two strings. (OT:) If you
are willing to limit portability to POSIX platforms and systems
which provide the function as an extension, you may use
strcasecmp().
-Micah
Eduardo Elias Camponez wrote: Hi Im doing a C code using GCC. I tried to compare (case Incensitive) two strings.. but it seems dont "know" strcmpi.. Im using 2 headers string.h and stdio.h How can I do this?
Ex: #include <stdio.h> #include <string.h>
int main (void) { char * str = "Case"; char * str1 = "cAsE";
if (strcmpi(str,str1)==0) printf("Same\n"); else printf("Sorry\n"); }
Tks
Eduardo Elias Camponez
Thank you for your post, Eduardo.
#include <stdio.h>
#include <string.h>
int main()
{
char * str = "Case";
char * str1 = "cAsE";
/* strcmp returns 0 if the two strings are identical */
if (!strcmp(str, str1))
printf("Same\n");
else
printf("Sorry\n");
return 0;
}
--Steve
Irrwahn Grausewitz <ir*****************@freenet.de> wrote in message news:<ba********************************@4ax.com>. .. "j" <ja*******@bellsouth.net> wrote:
"Eduardo Elias Camponez" <ca******@yahoo.com.br> wrote in message news:a3**************************@posting.google. com... Hi Im doing a C code using GCC. I tried to compare (case Incensitive) two strings.. but it seems dont "know" strcmpi.. Im using 2 headers string.h and stdio.h How can I do this?
Ex: #include <stdio.h> #include <string.h>
int main (void) { char * str = "Case"; char * str1 = "cAsE";
if (strcmpi(str,str1)==0) printf("Same\n"); else printf("Sorry\n"); }
Tks
Eduardo Elias Camponez
Just provide your own version of ``strcmpi'' .. although I think you might want to rename it, since str* is reserved by the implementation if I am not mistaken.
To be exact, ISO/IEC 9899:1999 states:
7.26.11 String handling <string.h> Function names that begin with str, mem, or wcs and a lowercase letter may be added to the declarations in the <string.h> header.
A perfectly valid name would be e.g.: strCmpi
Under C90, external identifiers need not be distinguishable by case,
and C90 implementations are only required to recognise external
identifiers up to 6 significant characters (IIRC).
So, strCmpi can theoretically have the same signature as strcmp,
STRCMP, StrCMP, StrCmp, etc...
--
Peter
Steve Zimmerman <st******@sonic.net> wrote: Eduardo Elias Camponez wrote:
Hi Im doing a C code using GCC. I tried to compare (case Incensitive) two strings.. but it seems dont
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ "know" strcmpi.. Im using 2 headers string.h and stdio.h How can I do this?
Thank you for your post, Eduardo.
#include <stdio.h> #include <string.h>
int main() { char * str = "Case"; char * str1 = "cAsE";
/* strcmp returns 0 if the two strings are identical */
if (!strcmp(str, str1)) printf("Same\n"); else printf("Sorry\n");
return 0; }
Steve,
how does this code compare two strings _case insensitive_?
Regards
Irrwahn
--
Great minds run in great circles. ai***@acay.com.au (Peter Nilsson) wrote: Irrwahn Grausewitz <ir*****************@freenet.de> wrote:
"j" <ja*******@bellsouth.net> wrote:
<SNIP> >Just provide your own version of ``strcmpi'' .. although I think you might >want to rename it, since str* is reserved by the implementation if I am not >mistaken. To be exact, ISO/IEC 9899:1999 states:
7.26.11 String handling <string.h> Function names that begin with str, mem, or wcs and a lowercase letter may be added to the declarations in the <string.h> header.
A perfectly valid name would be e.g.: strCmpi
Under C90, external identifiers need not be distinguishable by case, and C90 implementations are only required to recognise external identifiers up to 6 significant characters (IIRC).
So, strCmpi can theoretically have the same signature as strcmp, STRCMP, StrCMP, StrCmp, etc...
That's why I was referring to C99... :)
Irrwahn
--
Great minds run in great circles. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Jenski182 |
last post by:
Is this from a good coder? or a rubbish one? Whichever way, it was paid for his
services, just want to know if its worth while....
Thanks
Jen x
#include <iostream.h>
#include <conio.h>
|
by: threetoast |
last post by:
Is there any way to have a class function to search a struct, but the
field searched be passed to it as, say, a character array? Ex:
int book::searchChar(char r, char tyco)
{
for (int p=0; p<x;...
|
by: Michael Sgier |
last post by:
Hello
I want to replace a windows bitmap load function through an equivalent
SDL function.
I should extract the img height etc. and assign it to the terrainTex
array. I've also
three beginner...
|
by: GRoll21 |
last post by:
I know there is a function but I cannot seem to find it. There should
be a way to uppercase a char right?
Here is what I got.
cout << "Enter title of a book for look up: ";
cin >>...
|
by: chook |
last post by:
How i can call my function with some parameters,
if i have a pointer to this function
| |
by: Brett |
last post by:
I'm compiling a very small project with some matlab includes and getting an
internal compile error. There are no optimisations in this project, and I'm
not using managed code.
...
|
by: mansimisha |
last post by:
Hi to everybody.. I need a help need to have a program to represent
directory structure(a directory can contain any number of directory or
files) alos write a programme to insert one element nd...
|
by: hepsibasushmap |
last post by:
Hi all,
I had downloaded the Xerces C++ DOMLibrary and had also prepared a
parser which reads a file which is similar to our Menu.
Now in the similarway iam trying to prepare a parser for one...
|
by: J4CK4L |
last post by:
Hi everyone,
i want to compare a string whith another in a file called wordlist.txt
I've this code...
int Scan(char Search)
{
char *pch;
pch = strtok (Search," -,.");
while (pch != NULL)
{
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |