Write a program to compare two strings without using the
strcmp() function

Answer Posted / madiha

“PROGRAM THAT COPMPARE TWO STRINGS”

#include <iostream>
using namespace std;

int mycomp(char str1[],char str2[])
{
int i=0;
while(1)
{
if(str1[i]>str2[i])
return 1;
if(str1[i]<str2[i])
return -1;
else if(str1[i]=='\0'||str2[i]=='\0')
return 0;
i++;
}
}
int main()
{
cout<<mycomp("madiho","madiha");
return 0;
}

OUTPUT
1

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Describe the order of precedence with regards to operators in C.

631


What does calloc stand for?

643


Write a program to print numbers from 1 to 100 without using loop in c?

633


Why isnt there a numbered, multi-level break statement to break out

585


Which is best linux os?

558






How will you find a duplicate number in a array without negating the nos ?

1637


What does p mean in physics?

581


Explain what are its uses in c programming?

590


How can I sort a linked list?

633


What is the advantage of c?

607


What is storage class?

654


What is the difference between mpi and openmp?

731


Explain the meaning of keyword 'extern' in a function declaration.

718


Write a program to produce the following output: 1 2 3 4 5 6 7 8 9 10

15046


What are the standard predefined macros?

629