strncmp
int  strncmp ( const char * string1, const char * string2, sizet_t num );
string.h
  cplusplus.com  

Compare some characters of two strings.
  Compares the first num characters of string1 to the first num characters of string2.
  The comparison is performed character by character. If a character that is not equal in both strings is found the function ends and returns a value that determines which of them was greater.

Parameters.

string1
Null-terminated string to compare
string2
Null-terminated string to compare.
num
Maximum number of characters to compare.

Return Value.
  Returns a value indicating the lexicographical relation between the strings:

return valuedescription
<0string1 is less than string2
0string1 is the same as string2
>0string1 is greater than string2

Portability.
  Defined in ANSI-C.

Example.

/* strncmp example */
#include <stdio.h>
#include <string.h>

main ()
{
  char str[][5] = { "R2D2" , "C3PO" , "V4DR" , "C3A4" , "LUKE" };
  int n;
  printf ("Looking for human relations robots...\n");
  for (n=0 ; n&t;5 ; n++)
    if (strncmp (str[n],"C3**",2) == 0)
    {
      printf ("found %s\n",str[n]);
    }
  return 0;
}
Output:
Looking for human relations robots...
found C3PO
found C3A4

See also.
  strcat, strcpy, strncpy strset, memcpy


© The C++ Resources Network, 2000