Pages

Write a program in c language to compare two strings without strcmp function or any other function

Sunday 6 July 2014

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

int main()
{
   char str1[100], str2[100], ch;
   int i, check = 0, count = 0;

for(i=0; i<=100; i++)
{
str1[i] = str2[i] = 0;
}

   printf("Enter the first string: ");
   while(ch != 13)
   {
ch = getche();
str1[count] = ch;
count++;
   }
 
 
count = 0;
ch = NULL;
   printf("\nEnter the second string: ");
   while(ch != 13)
   {
ch = getche();
str2[count] = ch;
count++;
   }

for(i=0; i<=99; i++)
{
if(str1[i] != str2[i])
check = 1;
}


   if( check == 0 )
   {
      printf("\nEntered strings are equal.\n");
   }
   else
   {
      printf("\nEntered strings are not equal.\n");
   }
 
getch();
}

 

Search Box

Most Reading

Contact Form

Name

Email *

Message *