How to use the strcmp() function in C
The following example demonstrates how to use the strcmp() function in C:
C
// C Program to Demonstrate the use of strcmp() function #include <stdio.h> #include <string.h> int main() { // declaring two same string char * first_str = "Geeks" ; char * second_str = "Geeks" ; // printing the strings printf ( "First String: %s\n" , first_str); printf ( "Second String: %s\n" , second_str); // printing the return value of the strcmp() printf ( "Return value of strcmp(): %d" , strcmp (first_str, second_str)); return 0; } |
Output
First String: Geeks Second String: Geeks Return value of strcmp(): 0
C strcmp()
In C language, the <string.h> header file contains the Standard String Library that contains some useful and commonly used string manipulation functions. In this article, we will see how to compare strings in C using the function strcmp().