Write a program to compare two strings without using the
strcmp() function
Answer Posted / shashank kapoor
//PROGRAM TO COMPARE TWO STRINGS
#include<iostream.h>
#include<conio.h>
#include<string.h>
void main()
{
char str[10],ptr[10];
int 1,flag,a,b,x,y;
cout<<"Enter two strings:"<<endl;
cin>>str;
a=strlen(str);
cin>>ptr;
b=strlen(ptr);
for(i=0;i<(a>b?a:b);i++)
{
if(str[i]>ptr[i])
{
x=str[i]-ptr[i];
flag=1;
}
else if(str[i]<ptr[i])
{
y=str[i]-ptr[i];
flag=2;
}
}
if(flag==1)
cout<<"Str is greater than Ptr by: "<<x;
else if(flag==2)
cout<<"Str is smaller than Ptr by: "<,y;
else
cout<<"Str & Ptr are EQUAL";
getch();
}
| Is This Answer Correct ? | 3 Yes | 1 No |
Post New Answer View All Answers
Can a variable be both const and volatile?
what is the c source code for the below output? 10 10 10 10 10 10 10 10 10 10 9 9 7 6 6 6 6 6 6 9 7 5 9 7 3 2 2 5 9 7 3 1 5 9 7 3 5 9 7 4 4 4 4 5 9 7 8 8 8 8 8 8 8 8 9
What is printf () in c?
program to convert a integer to string in c language'
What is nested structure in c?
What do you mean by Recursion Function?
What are the loops in c?
Define Spanning-Tree Protocol (STP)
WRITE A CODE IN C TO SEARCH A FILE FROM NOTEPAD FILE.
A collection of functions,calls,subroutines or other data a) library b) header files c) set of files d) textfiles
Iam a B.Tech graduate and completed my engineering in 2009, from 2005 to 2009 and after that i had done nothing.Now i want to do job and get into BPO field . Friends give me suggestions as what to say in interview... if they ask me that what would you had done ... these many years without doing job ??????? pls urgent
Can variables be declared anywhere in c?
How can I make sure that my program is the only one accessing a file?
Is it better to use a pointer to navigate an array of values, or is it better to use a subscripted array name?
What are the general description for loop statement and available loop types in c?