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


strcmp

Compare two character arrays.

Compatibility:

This function is compatible with the following targets:

ANSI

BeOS

EMB/RTOS

Mac OS

Palm OS

Win32


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

Parameters for this facility are:

s1  
const char *  
The string to compare  
s2  
const char *  
The comparison string  

Remarks:

The strcmp() function compares the character array pointed to by s1 to the character array pointed to by s2. Both s1 and s2 must point to null terminated character arrays.

Return:

strcmp() returns a zero if 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"

"strcoll"

"strncmp"

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

int main (void)
{
	static char s1[] = "butter", s2[] = "olive oil";
	char dest[20];
	
	if (strcmp(s1, s2) < 0)
		strcpy(dest, s2);
	else
		strcpy(dest, s1);

	printf(" s1=%s\n s2=%s\n dest=%s\n", s1, s2, dest);

	return 0;
}

Output:
 s1=butter
 s2=olive oil
 dest=olive oil


[ 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