C Function Strcmp
# C Library Function - strcmp()
[ C Standard Library - ](#)
## Description
The C library function **int strcmp(const char *str1, const char *str2)** compares the string pointed to by **str1** to the string pointed to by **str2**.
## Declaration
Below is the declaration for the strcmp() function.
int strcmp(const char *str1, const char *str2)
## Parameters
* **str1** -- The first string to be compared.
* **str2** -- The second string to be compared.
## Return Value
This function returns values as follows:
* If the return value is less than 0, it indicates str1 is less than str2.
* If the return value is greater than 0, it indicates str1 is greater than str2.
* If the return value is equal to 0, it indicates str1 is equal to str2.
## Example
The following example demonstrates the usage of the strcmp() function.
## Example
#include#includeint main(){char str1; char str2; int ret; strcpy(str1, "abcdef"); strcpy(str2, "ABCDEF"); ret = strcmp(str1, str2); if(ret0){printf("str1 is greater than str2"); }else{printf("str1 is equal to str2"); }return(0); }
Let us compile and run the above program, which will produce the following result:
str1 is greater than str2
[ C Standard Library - ](#)
YouTip