< C++ Programming < Code < Standard C Library < Functions

strncmp

Syntax
#include <cstring>
int strncmp( const char *str1, const char *str2, size_t count );

The strncmp() function compares at most count characters of str1 and str2. The return value is as follows:

Return valueExplanation
less than 0str1 is less than str2
equal to 0str1 is equal to str2
greater than 0str1 is greater than str2

If there are less than count characters in either string, then the comparison will stop after the first null termination is encountered.

Related topics
strchr - strcmp - strcpy - strlen - strncat - strncpy
This article is issued from Wikibooks. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.