Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

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


Please Help Members By Posting Answers For Below Questions

What is the general form of function in c?

1071


Define macros.

1328


How can I find out how much free space is available on disk?

1104


while initialization of array why we use a[][2] why not a[2][]...?

2401


Is r written in c?

1189


What is structure in c language?

1237


I just typed in this program, and it is acting strangely. Can you see anything wrong with it?

1055


When should a type cast not be used?

1108


which of the following is not a character constant a) 'thank you' b) 'enter values of p, n ,r' c) '23.56E-o3' d) all of the above

2121


What is sizeof int?

1152


What is the value of c?

1130


How many types of operators are there in c?

1088


Why is C language being considered a middle level language?

1208


Function calling procedures? and their differences? Why should one go for Call by Reference?

1134


What is register variable in c language?

1062