Chapter Contents

Previous

Next
strcasecmp

strcasecmp



Compare Two Null-Terminated strings, ignoring differences in case

Portability: SAS/C


SYNOPSIS
DESCRIPTION
RETURN VALUE
CAUTION
IMPLEMENTATION
EXAMPLE
RELATED FUNCTIONS
SEE ALSO


SYNOPSIS

#include <strings.h>

int strcasecmp( const char *str1, const char *str2 );


DESCRIPTION

strcasecmp compares, while ignoring differences in case, two character strings specified by str1 and str2. The comparison is performed using the standard EBCDIC collating sequence with the exception that differences in case are ignored. The return value has the same relationship to 0 as str1 has to str2. If the two strings are equal up to the point at which one terminates (that is, contains a null character), the longer string is considered greater. Note that case differences are determined in a locale- specific manner.


RETURN VALUE

strcasecmp returns 0 if the two strings are equal, an integer less than 0 if str1 compares less than str2, or an integer greater than 0 if str1 compares greater than str2. No other assumptions should be made about the value returned by strcasecmp.


CAUTION

If one of the arguments of strcasecmp is not properly terminated, a protection or addressing exception may occur.


IMPLEMENTATION

strcasecmp is functionally equivalent to strcmp, except that each byte is converted to lowercase before the comparison is performed.


EXAMPLE

#include <strings.h>
int main(void)
{
   int ch;
   char lwr_alpha[] = "abcdefghijklmnopqrstuvwxyz";
   char upr_alpha[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
   char mix_alpha[] = "AbCdEfGhIjKlMnOpQrStUvWxYz";

   ch = strcasecmp(lwr_alpha, mix_alpha);
   if ( ch != 0 )
   {
      exit(EXIT_FAILURE);
   }
   
   ch = strcasecmp(upr_alpha, mix_alpha);
   if ( ch != 0 )
   {
      exit(EXIT_FAILURE);
   }
   
   exit(EXIT_SUCCESS);
}


RELATED FUNCTIONS

strcmp, memcasecmp, memcmp, strncasecmp, strncmp


SEE ALSO

"String Utility Functions" in Chapter 2, "Function Categories."


Chapter Contents

Previous

Next

Top of Page

Copyright © 2004 by SAS Institute Inc., Cary, NC, USA. All rights reserved.