CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Standard C function for strings

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Lemosek



Joined: 15 Oct 2011
Posts: 36

View user's profile Send private message

Standard C function for strings
PostPosted: Sat Oct 06, 2012 5:37 am     Reply with quote

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

View user's profile Send private message

PostPosted: Sat Oct 06, 2012 9:20 am     Reply with quote

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

View user's profile Send private message

PostPosted: Sat Oct 06, 2012 9:49 am     Reply with quote

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: 19506

View user's profile Send private message

PostPosted: Sat Oct 06, 2012 2:32 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Sun Oct 07, 2012 11:50 am     Reply with quote

Hello,
Thank You very much, this is exactly what I need Smile.

best regards
R.L.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group