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
How many types of errors are there in c language? Explain
How do I get an accurate error status return from system on ms-dos?
What is p in text message?
What are all different types of pointers in c?
i have to apply for rbi before that i need to know the the syllabus for the entrance questions. whethet it may be aps or techinical
what is a NULL Pointer? Whether it is same as an uninitialized pointer?
How can I handle floating-point exceptions gracefully?
What is a class c rental property?
WRITE A CODE IN C TO SEARCH A FILE FROM NOTEPAD FILE.
What is the condition that is applied with ?: Operator?
what does static variable mean?
What is a void pointer? When is a void pointer used?
Why can’t we compare structures?
In c programming typeing to occupy the variables in memory space. if not useing the variable the memory space is wasted.ok, how to avoid the situation..? (the variable is used & notused)
can we implement multi-threads in c.