EmbLogic's Blog

c program to compare two string without using string.h

#include
int main()
{
char s1[5],s2[5];
int i,j,flag=0;

printf(“Enter s1:”);
scanf(“%s”,s1);
printf(“Enter s2:”);
scanf(“%s”,s2);
for(i=0;i<5;i++)
{
if(s1[i]!=s2[i])
{
j=s1[i]-s2[i];
flag=1;
printf("return value: %d\n",j);
break;
}
}
if(flag==0)
printf("string matched\n");

return 0;
}

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>