20/03/2016

C Program to Compare Two Strings Using strcmp

Problem:- C Program to Compare Two Strings Using strcmp or C program to compare two strings or C Program to Compare Two Strings using strcmp() or C Program to Accepts two Strings & Compare them or C Program to Compare Two Strings Using Library Function or C Program to Compare Two Strings Using strcmp() Function or strcmp function (String Compare) or Compare two string using strcmp function.

Check This:- Hacker rank solution for Strings, Classes, STL, Inheritance in C++.

Explanation:- Comparing a two string using an inbuilt library function is very simple first we have to take an input (both string, you want to compare ) from user and use a compare inbuilt function if both strings are equal then strcmp return zero and if the both string is not compared then return value by inbuilt function is not equal to zero. The strcmp() function syntax is given below we have to just take an input and put the string in strcmp() library function.

Syntax of strcmp()

strcmp(string1, string2);

where string1 and string2 both are two different-different string we have to compare.


Also Check:- Geeksforgeeks solution for School, Basic, Easy, Medium, Hard in C++.


Extreme Recommended:- Like our Facebook Page or Join our Facebook Group and Google plus Community for up-to-date for a new post or if you have any Query you can ask there with lots of coders also suggest to your Friends to join and like our page.


Solution:-

#include<stdio.h>
#include<string.h>

void main()
{
/*Visit - www.programmingwithbasics.com*/
   
    printf("=====================================");
    printf("\nVisit - www.programmingwithbasics.com");
    printf("\n=====================================");

while(1)
{
    char a[100], b[100];

    printf("\n\nEnter The First String: ");
    gets(a);

    printf("\n\nEnter The Second String: ");
    gets(b);

    if (strcmp(a,b) == 0)
      printf("\n\nStrings Are Equal\n");
    else
      printf("\n\nStrings Are Not Equal");
}
   return 0;
}

Output:-

C Program to Compare Two Strings Using strcmp

You May Also See


1. Java Program To Find Greater No. Among given Three Number

2. Java Program For Find The Gross Salary Of An Employee


Previous Post
Next Post

post written by:

Hi, I’m Ghanendra Yadav, SEO Expert, Professional Blogger, Programmer, and UI Developer. Get a Solution of More Than 500+ Programming Problems, and Practice All Programs in C, C++, and Java Languages. Get a Competitive Website Solution also Ie. Hackerrank Solutions and Geeksforgeeks Solutions. If You Are Interested to Learn a C Programming Language and You Don't Have Experience in Any Programming, You Should Start with a C Programming Language, Read: List of Format Specifiers in C.
Follow Me

0 Comments: