Guardian C Library Calls Reference Manual

strcmp
3-194 128833Guardian TNS C Library Calls Reference Manual
Reference to Library Calls
strcmp
The strcmp function compares two strings alphabetically.
str1_ptr
points to the first string.
str2_ptr
points to the second string.
Return Value
is zero if the two strings are equal, a negative value if *str1_ptr is less than
*str2_ptr, or a positive value if *str1_ptr is greater than *str2_ptr.
Usage Guidelines
If the two strings are different lengths but match to the end of the shorter string, the
shorter string is considered less than the longer string.
Example
This example compares two strings and prints “s1 is greater than s2”:
#include <stringh>
#include <stdioh>
int main(void)
{
int value;
char *s1;
char *s2;
s1 = "Opus is a penguin";
s2 = "Opus is a flightless water fowl";
value = strcmp(s1,s2);
/* prints "s1 is greater than s2" because */
/* 'p' is greater than 'f' */
if (value<0)
printf("s1 is less than s2\n");
else if (value>0)
printf("s1 is greater than s2\n");
else
printf("s1 equals s2\n");
}
#include <stringh>
int strcmp(const char *str1_ptr, const char *str2_ptr);