qh_strcmp()

Updated: April 19, 2023

Safely compare two strings

Synopsis:

#include <qh/string.h>
int qh_strcmp(const char *str1,
              const char *str2)

Arguments:

str1
The first string to compare, or NULL.
str2
The second string to compare, or NULL.

Library:

qh

Description:

The qh_strcmp() function compares the string that str1 points to the one that str2 points to. A NULL argument is valid and compares as smaller to a non-NULL string and as equal to another NULL string.

Returns:

  • -2 if str1 is NULL and str2 is not
  • 2 if str2 is NULL and str1 is not
  • If str1 and str2 are not NULL:
    • < 0 if str1 is less than str2
    • 0 if str1 is equal to str2
    • > 0 if str1 is greater than str2