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
Explain the difference between strcpy() and memcpy() function?
Can you subtract pointers from each other? Why would you?
How can I call a function with an argument list built up at run time?
Are pointers integers in c?
What is FIFO?
The number of measuring units from an arbitarary starting point in a record,area,or control block to some other point a) recording pointer b) offset c) branching d) none
What is a method in c?
Write a program to find factorial of a number using recursive function.
write a program to rearrange the array such way that all even elements should come first and next come odd
Is c is a high level language?
What is the best way to comment out a section of code that contains comments?
An expression to whose value an operater is applied a) operand b) variable c) constant d) all of the above
how many types of operators are include in c language a) 4 b) 6 c) 8 d) 12
What are the uses of null pointers?
What are the benefits of c language?