View previous topic :: View next topic |
Author |
Message |
Lemosek
Joined: 15 Oct 2011 Posts: 36
|
Standard C function for strings |
Posted: Sat Oct 06, 2012 5:37 am |
|
|
Hello,
I have small problem. I want compare two string and i find strncasecmp function, but in CCS is only strncmp. This function recognize big and small symbols, like A is not a. In my program I don't need this.
For me "aaa" must be egual with "AAA".
How I can do this ??
Best regards
R.L. |
|
|
gpsmikey
Joined: 16 Nov 2010 Posts: 588 Location: Kirkland, WA
|
|
Posted: Sat Oct 06, 2012 9:20 am |
|
|
Does stricmp(s1,s2) not do what you want ? - see the "standard string functions" section in the user manual for what is available.
mikey _________________ mikey
-- you can't have too many gadgets or too much disk space !
old engineering saying: 1+1 = 3 for sufficiently large values of 1 or small values of 3 |
|
|
Lemosek
Joined: 15 Oct 2011 Posts: 36
|
|
Posted: Sat Oct 06, 2012 9:49 am |
|
|
Hello,
Thank You for reply.
Yes this function doing this but for all string. In function strncmp I have third parameter s3 - number of characters from each string to be used in the comparison.
Best regards
R.L. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19514
|
|
Posted: Sat Oct 06, 2012 2:32 pm |
|
|
just write it.
Code: |
int strncmpn(char* s1, char* s2, int n) {
if (n==0) return 0;
while (n-- != 0 && tolower(*s1) == tolower(*s2)) {
if (n == 0 || *s1 == '\0' || *s2 == '\0')
break;
s1++;
s2++;
}
return tolower(*(unsigned char *) s1) - tolower(*(unsigned char *) s2);
}
|
There is nothing magical about any of the functions. strncasecmp, is a non standard function that was included in quite a few unix/linux distributions, but because it was _not_ part of C, the source was included as well in the include library.
Best Wishes |
|
|
Lemosek
Joined: 15 Oct 2011 Posts: 36
|
|
Posted: Sun Oct 07, 2012 11:50 am |
|
|
Hello,
Thank You very much, this is exactly what I need .
best regards
R.L. |
|
|
|