Q:

C Program to Compare Two Strings Using strcmp

belongs to collection: String in C Programs

0

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.

 

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.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

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

void main()
{
    printf("=====================================");
    printf("\nnerdutella.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:

==============================

nerdutella.com

==============================

Enter The First String :programming

Enter The Second String :example

Strings Are Not Equal

Enter The First String:programming

Enter Th Second String:progeamming

Strings Are Equal

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

C Program to Count Vowels, Consonants, Digits and ... >>
<< Program to Reverse a String in C | Using Loop, Rec...