Sunday, 20 March 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


Extreme Recommended:- Like our Facebook Page or Join our Facebook Group and Google plus Community for up-to-date. If you have any Query or Question you can ask in the group, I will Try To Solve your Query and try to answers of your Questions withing 24 Hours, You can also Email me or comment below Please suggest to your Friends to join and like our page and don't forget to Subscribe. Enter your Email and click to subscribe.

Ghanendra Yadav

Ghanendra Yadav

Hello, I Am Ghanendra Yadav Owner of This Blog, I am professional Blogger and Programmer. I Love Programming, Logo Making, And Banner Designing. My Highest Qualification is MCA From NIT Warangal. You Can Find Me On Social Media Through Below Link And If You Have Any Query Related To Programming And Other Subject Comment Below or You Can Mail Me I Will Try To Answer Within 24 Hours Email:- yghanendra@student.nitw.ac.in

Find me on Social Media

Facebook | Twitter | Google+ | RSS Feed

No comments:

Post a Comment