ILE C/C++ Run-Time Library Functions


strcasecmp() -- Compare Strings without Case Sensitivity

Format

#include <strings.h>
int srtcasecmp(const char *string1, const char *string2);

Language Level: XPG4

Threadsafe: Yes.

Description

The strcasecmp() function compares string1 and string2 without sensitivity to case. All alphabetic characters in string1 and string2 are converted to lowercase before comparison.

The strcasecmp() function operates on null terminated strings. The string arguments to the function are expected to contain a null character ('\0') marking the end of the string.

Return Value

The strcasecmp() function returns a value indicating the relationship between the two strings, as follows:


Table 6. Return values of

strcasecmp()

Value Meaning
Less than 0 string1 less than string2
0 string1 equivalent to string2
Greater than 0 string1 greater than string2

Example that usesstrcasecmp()

This example uses strcasecmp() to compare two strings.

#include <stdio.h>
#include <strings.h>
 
int main(void)
{
  char_t *str1 = "STRING";
  char_t *str2 = "string";
  int result;
 
  result = strcasecmp(str1, str2);
 
  if (result == 0)
    printf("Strings compared equal.\n");
  else if (result < 0)
    printf("\"%s\" is less than \"%s\".\n", str1, str2);
  else
    printf("\"%s\" is greater than \"%s\".\n", str1, str2);
 
  return 0;
}
 
/********  The output should be similar to: ***************
 
Strings compared equal.
 
***********************************/

Related Information


[ Top of Page | Previous Page | Next Page | Table of Contents | Index ]