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
How can I convert a number to a string?
What do you mean by invalid pointer arithmetic?
Why is struct padding needed?
What is main return c?
write an algorithm to display a square matrix.
What is a far pointer in c?
What is volatile, register definition in C
design and implement a data structure and performs the following operation with the help of file (included 1000 student marks in 5 sub. and %also) 1.how many students are fail in all 5 subjects (if >35) 2. delete all student data those are fail in all 5 subjects. 3. update the grace marks (5 no. if exam paper is 100 marks) 4. arrange the student data in ascending order basis of marks. 5.insert double of deleted students with marks in the list.
Can you explain what keyboard debouncing is, and where and why we us it? please give some examples
When can you use a pointer with a function?
Once I have used freopen, how can I get the original stdout (or stdin) back?
what is a NULL Pointer? Whether it is same as an uninitialized pointer?
How can I read in an object file and jump to locations in it?
Explain with the aid of an example why arrays of structures don’t provide an efficient representation when it comes to adding and deleting records internal to the array.
Explain threaded binary trees?