strcmp

Compares two strings (function or macro)

Local Servers:nonblocking
Remote Servers:N/A
Classification:ANSI
Service:String Manipulation

Syntax

  #include <string.h>  
   
  int strcmp  (  
     const char   *s1,   
     const char   *s2);
  

Parameters

s1
(IN) Points to the string to be compared to the string pointed to by s2.
s2
(IN) Points to the string to be compared to the string pointed to by s1.

Return Values

strcmp returns an integer less than, equal to, or greater than zero, indicating that the string pointed to by s1 is less than, equal to, or greater than the string pointed to by s2.

Remarks

The strcmp function or macro compares the string pointed to by s1 to the string pointed to by s2.

See Also

stricmp, strncmp, strnicmp

Example

  #include <string.h>  
  #include <stdio.h>  
   
  main ()  
  {  
     printf ("%d\n", strcmp ("abcdef", "abcdef") );  
     printf ("%d\n", strcmp ("abcdef", "abc") );  
     printf ("%d\n", strcmp ("abc", "abcdef") );  
     printf ("%d\n", strcmp ("abcdef", "mnopqr") );  
     printf ("%d\n", strcmp ("mnopqr", "abcdef") );  
  }
  

produces the following:

  0  
  1  
  -1  
  -1  
  1