Compare String using STRCMP() – C Program

STRCMP() Function – C Program

Write a c program to compare two string using STRCMP() function.

STRCMP() Function – The STRCMP() Function used to compare two string, either it equal or not.

The Syntax of STRCMP() Function :

strcmp(str1, str2)  == 0 – both string str1 and str2 are equal.
strcmp(str1, str2)  !=0 – both string str1 and str2 are not equal.

Example of STRCMP() Function C Program

#include<stdio.h>
 
int main()
{

char str1[100], str2[100];

printf("Please enter the first string = ");
gets(str1);
 
printf("\nPlease enter the second string = ");
gets(str2);
 

if(strcmp(str1,str2) == 0)
 {
  printf("\nThe strings are equal");
  }
 else
 {  
 printf("\nThe strings are not equal");
 } 

return 0;
}

The String Compare C Program output is :

Please enter the first string = meera
Please enter the second string = meera

The strings are equal

////////////////////

Please enter the first string = meera
Please enter the second string = ram

The strings are not equal

 

 

Author: Meera Academy

Leave a Reply

Your email address will not be published. Required fields are marked *