strncmp

Compares a specified number of characters between two strings

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

Syntax

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

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.
n
(IN) Specifies the number of characters to be compared.

Return Values

The strncmp function returns an integer less than, equal to, or greater than 0, indicating that the string pointed to by s1 is less than, equal to, or greater than the string pointed to by s2.

Remarks

The strncmp function compares not more than n characters from the string pointed to by s1 to the string pointed to by s2.

See Also

strcmp, stricmp, strnicmp

Example

  #include <string.h>  
  #include <stdio.h> 
    
  main ()  
  {  
     printf ("%d\n", strncmp ("abcdef", "abcDEF", 10) );  
     printf ("%d\n", strncmp ("abcdef", "abcDEF",  6) );  
     printf ("%d\n", strncmp ("abcdef", "abcDEF",  3) );  
     printf ("%d\n", strncmp ("abcdef", "abcDEF",  0) );  
  }
  

produces the following:

   1  
   1  
   0  
   0