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 / sanskriti jain

#include<iostream.h>
#include<conio.h>
#include<stdio.h>
void main()
{
clrscr();
char a[50],b[50];
int c,i=0;
cout<<"\n Enter the first string:\n";
gets(a);
cout<<"\n Enter the second string:\n";
gets(b);
while (a[i]!='\0'||b[i]!='\0')
{
c=(a[i]-b[i]);
if(c!=0)
break;
i++;
}
if(c>0)
cout<<"a comes after b\n"<<a<<"\n"<<b;
else
{
if(c<0)
cout<<"b comes after a\n"<<b<<"\n"<<a;
else
cout<<"Both the string are same\n"<<a;
}
getch();
}

Is This Answer Correct ?    1 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What are the types of unary operators?

1249


What's the difference between constant char *p and char * constant p?

1191


What is class and object in c?

1172


What is a structure and why it is used?

1291


What are the application of void data type in c?

1228


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)

2171


about c language

2069


What is volatile, register definition in C

1146


What is pointers in c with example?

1133


How important is structure in life?

1143


What are the restrictions of a modulus operator?

1163


What is the value of h?

1083


Explain what is operator promotion?

1145


Why can arithmetic operations not be performed on void pointers?

1093


Are c and c++ the same?

1103