C

How To Compare Two Strings in C Using strcmp

In this tutorial, we are going to see how to compare two strings in C using strcmp. we can use the strcmp function of the C library. strcmp can be used to compare two strings. If it returns 0, then the two strings are equal if it does not return 0, then the two strings are not equal.
100-multiple-choice-questions-in-c-programming100 Multiple Choice Questions In C Programming – Part 1This collection of 100 Multiple Choice Questions and Answers (MCQs) In C Programming : Quizzes & Practice Tests with Answer focuses on “C Programming”.  …Read More

How To Compare Two Strings in C Using strcmp
#include <stdio.h>
#include <string.h>
 
int main()
{
   char str1[100], str2[100];
 
   printf("Enter the first string: ");
   gets(str1);

   printf("Enter the second string: ");
   gets(str2);
 
   if (strcmp(str1,str2) == 0)
      printf("Both string are equal.\n");
   else
      printf("Both string are not equal.\n");
 
   return 0;
}

Output:

Enter the first string: StackHowTo
Enter the second string: google
Both string are not equal.

 

mcqMCQPractice competitive and technical Multiple Choice Questions and Answers (MCQs) with simple and logical explanations to prepare for tests and interviews.Read More

Leave a Reply

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