Adsense 728 * 15

Search

Custom Search

Write a Program to Compare Two Strings Using strcmp()


In my previous tutorials i talked about Strings and StringPrograms.

In this tutorial, i show you how to compare two strings using strcmp(). strcmp() compares two function and return 0 if string is equal.

Program to Compare Two Strings Using strcmp()



#include <stdio.h>
#include <string.h>
 
void main()
{
   char str1[100], str2[100];
 
   printf("Enter the first string\n");
   gets(str1);
 
   printf("Enter the second string\n");
   gets(str2);
 
   // If string is equal it returns zero
   if( strcmp(str1,str2) == 0 ) 
      printf("Strings are equal.\n");
   else
      printf("Strings are not equal.\n");
 
   
}


No comments:

Post a Comment