STRING COMPARISON WITHOUT USING LIBRARY FUNCTION - C-Tutorial

Latest

Monday, 26 September 2016

STRING COMPARISON WITHOUT USING LIBRARY FUNCTION

/* PROGRAM FOR STRING COMPARISON WITHOUT USING LIBRARY FUNCTION */


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

main()
{
char str1[10],str2[10];
int i,r=0;
clrscr();
printf("\n Enter a string1 :");
gets(str1);
printf("\n Enter a string2 :");
gets(str2);
for(i=0; str1[i]!='\0' && str2[i]!='\0'; i++)
{
if(str1[i]!=str2[i])
{
r=str1[i]-str2[i];
break;
}
}
if(r>0)
printf("\n String1 is greater than string2 ");
else if(r<0)
printf("\n String1 is less than string2 ");
else
printf("\n Both string1 and string2 are equal ");
getch();
}

No comments:

Post a Comment