[ First ]  [ Previous ]  [ Next ]  [ Last ]  [ Manuals ]


strncmp

Compare a specified number of characters.

Compatibility:

This function is compatible with the following targets:

ANSI

BeOS

EMB/RTOS

Mac OS

Palm OS

Win32


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

Parameters for this facility are:

s1  
const char *  
The string to compare  
s2  
const char *  
The comparison string  
n  
size_t  
The maximum number of characters to compare  

Remarks:

The strncmp() function compares n characters of the character array pointed to by s1 to n characters of the character array pointed to by s2. Neither s1 nor s2 needs to be null terminated character arrays.

The function stops prematurely if it reaches a null character before n characters have been compared.

Return:

strncmp() returns a zero if the first n characters of s1 and s2 are equal, a negative value if s1 is less than s2, and a positive value if s1 is greater than s2.

See Also:

"memcmp"

"strcmp"

Example of strncmp() usage.:
#include <string.h>
#include <stdio.h>

int main(void)
{
	static char s1[] = "12345anchor", s2[] = "12345zebra";

	if (strncmp(s1, s2, 5) == 0)
		printf("%s is equal to %s\n", s1, s2);
	else
		printf("%s is not equal to %s\n", s1, s2);

	return 0;
}

Output:
12345anchor is equal to 12345zebra


[ First ]  [ Previous ]  [ Next ]  [ Last ]  [ Manuals ]

Visit the Metrowerks website at: http://www.metrowerks.com
For assistance contact Metrowerks Technical Support at: cw_support@metrowerks.com
Copyright © 2000, Metrowerks Corp. All rights reserved.

Last updated: August 16, 2000