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 is the difference between test design and test case design?

1564


What are the types of data types and explain?

665


What does %p mean?

588


What does return 1 means in c?

579


Explain what is wrong in this statement?

632






What are different types of operators?

592


Why doesnt the call scanf work?

665


What are the advantages of using linked list for tree construction?

639


What is the use of a semicolon (;) at the end of every program statement?

764


Explain bit masking in c?

633


What is string concatenation in c?

565


1) write a program to generate 1st n fibonacci prime numbers using Nested if 2) write a program to generate twin prime numbers from m to n using nested if 3) write a program to check whether a given integer is a strong number or not using nested if 4) Write a program to generate prime factors of a given integer using nested if 5)write a program to generate prime numbers from m to n using nested if 6)write a program to generate perfect numbers from m to n using nested if 7)write a program to generate the pallindromes from m to n using neste if 8)write a program to generate armstrong numbers from m to n using nested if 9)write a program to generate strong numbers from m to n using nested if

3975


write a program to rearrange the array such way that all even elements should come first and next come odd

1758


can we have joblib in a proc ?

1650


Why is %d used in c?

559