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
What does dm mean sexually?
Which function in C can be used to append a string to another string?
Can you please compare array with pointer?
can anyone please tell about the nested interrupts?
Why is c so powerful?
What is the basic structure of c?
What are the functions to open and close the file in c language?
Is it fine to write void main () or main () in c?
Write a program to swap two numbers without using a temporary variable?
What is dynamic variable in c?
What Is The Difference Between Null And Void Pointer?
What is the function of this pointer?
How to write a multi-statement macro?
In this problem you are to write a program that will cut some number of prime numbers from the list of prime numbers between 1 and N.Your program will read in a number N; determine the list of prime numbers between 1 and N; and print the C*2 prime numbers from the center of the list if there are an even number of prime numbers or (C*2)-1 prime numbers from the center of the list if there are an odd number of prime numbers in the list.
How can my program discover the complete pathname to the executable from which it was invoked?