English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
C Standard Library - <string.h>
Usage and example of the C library function strcmp() int strcmp(const char *str1, const char *str2) The following is the C library function str1 The string pointed to by the argument and str2 The string pointed to by the argument is compared.
Below is the declaration of the strcmp() function.
int strcmp(const char *str1, const char *str2)
The return value of this function is as follows:
The following example demonstrates the usage of the strcmp() function.
#include <stdio.h> #include <string.h> int main () { char str1[15]; char str2[15]; int ret; strcpy(str1, "abcdef"); strcpy(str2, "ABCDEF"); ret = strcmp(str1, str2); if (ret < 0) { printf("str1 Less than str2"); {} else if(ret > 0) { printf("str1 Greater than str2"); {} else { printf("str1 Equal to str2"); {} return(0); {}
Let's compile and run the above program, which will produce the following result:
str1 Greater than str2