Write a program to compare two strings without using the
strcmp() function
Answer Posted / abhi
#include<stdio.h>
#include<conio.h>
main()
{
char *s1;
char *s2;
int flag=0;
s1=(char *)malloc(10);
s2=(char *)malloc(10);
scanf("%s",s1);
scanf("%s",s2);
while((*s1!='\0')||(*s2!='\0'))
{
if(*s1!=*s2)
flag=1;
else
{
s1++;
s2++;
}
if(flag)
{
if(*s1<*s2)
flag=-1;
break;
}}
if(*s1=='\0'&&*s2!='\0')
flag=-1;
else if(*s1!='\0'&&*s2=='\0')
flag=1;
else
{}
printf("%d",flag);
getch();
}
Is This Answer Correct ? | 4 Yes | 1 No |
Post New Answer View All Answers
Does * p ++ increment p or what it points to?
What is printf () in c?
What is string length in c?
What is define c?
Is there a way to compare two structure variables?
‘ C’ PROGRAME TO SHOW THE TYPE OF TRANGLE BY ACCEPTING IT’S LENGTH .
Explain how can I manipulate strings of multibyte characters?
Is fortran still used today?
How can I sort more data than will fit in memory?
When should I declare a function?
Why is extern used in c?
Do you know the use of 'auto' keyword?
Which built-in library function can be used to match a patter from the string?
What is array in c with example?
Why header files are used?