About Me

My photo
Raipur, Chhattisgarh, India
Hi , I am Amit Thakur. I have worked as a QA Engineer for two years and as a Java Developer for one year in NIHILENT TECHNOLOGIES PVT. LTD., Pune.Currently I am working as DEAN (Research & Development) in Bhilai Institute of Technology, Raipur.

Wednesday, September 4, 2013

C Program to Compare Two Strings Without Using Library Function

#include<stdio.h>
#include<conio.h>
void main()
{
char str1[30],str2[30];
int i;

printf("\n Enter two strings :");
gets(str1);
gets(str2);

//loop for comparison
 i=0;
 while(str1[i]==str2[i] && str1[i]!='')
  i++;
 if(str1[i] > str2[i])
  printf("\nstr1 > str2");
 else
  if(str1[i] < str2[i])
   printf("\nstr1 < str2");
  else
   printf("\nstr1 = str2");
 getch();
}

1 comment:

zzzzz said...

Here is a similar c program to compare two strings using pointers Two C strings are said to be same if they contains same characters in same sequence.