Thursday, 20 September 2012

c program to compare two strings


This c program compares two strings using strcmp, without strcmp and using pointers. For comparing strings without using library function see another code below.

C program to compare two strings using strcmp

#include<stdio.h>
#include<string.h>
 
main()
{
   char a[100], b[100];
 
   printf("Enter the first string\n");
   gets(a);
 
   printf("Enter the second string\n");
   gets(b);
 
   if( strcmp(a,b) == 0 )
      printf("Entered strings are equal.\n");
   else
      printf("Entered strings are not equal.\n");
 
   return 0;
}

No comments:

Post a Comment