Names specified here
Name Description Notes Source Availability
strcmp() Compare string (·) <string.h> C89 C90 C95 C99 C11
strncmp() Compare string (·) <string.h> C89 C90 C95 C99 C11
wcscmp() Compare wide-character string (·) <wchar.h> C95 C99 C11
wcsncmp() Compare wide-character string (·) <wchar.h> C95 C99 C11
#include <string.h>
int strcmp(const char *s1, const char *s2);
int strncmp(const char *s1, const char *s2, size_t n);
#include <wchar.h>
int wcscmp(const wchar_t *s1, const wchar_t *s2);
int wcsncmp(const wchar_t *s1, const wchar_t *s2, size_t n);

strcmp and wcscmp compare two null-terminated strings s1 and s2 of bytes or wide characters respectively. Starting from index 0, each pair of elements at index i is compared. The functions stop when the elements differ, or are both null. The functions return an integer with the same sign as s1[i] - s2[i]. Zero therefore indicates that the strings are identical at least to the point where the comparison reached. Positive and negative values then indicate a relative ordering of the two strings. Such return values are compatible with the comparison functions required by qsort and bsearch.

strncmp and wcsncmp do the same as strcmp and wcscmp, but also stop when n pairs of elements have been compared, returning zero.

See also strcoll and wcscoll for a more sophisticated form of string comparison.


CHaR
Sitemap Supported
Site format updated 2024-06-05T22:37:07.391+0000
Data updated 1970-01-01T00:00:00.000+0000
Page updated 2022-06-17T21:43:05.000+0000