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
What is selection sort in c?
What are the two types of structure?
What does != Mean in c?
code for quick sort?
how do you programme Carrier Sense Multiple Access
write a program to print the consecutive repeated character from the given string... input string is : hhhhjkutskkkkkggggj output should be like this: hhhhkkkkkgggg anyone help me...
What are the advantages of using Unions?
Explain 'far' and 'near' pointers in c.
Why can't I perform arithmetic on a void* pointer?
What are the advantages of using macro in c language?
What’s a signal? Explain what do I use signals for?
please explain every phase in the "SDLC" in the dotnet.
What is the code for 3 questions and answer check in VisualBasic.Net?
State two uses of pointers in C?
How pointers are declared?