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
Is it acceptable to declare/define a variable in a c header?
What do header files do?
Can include files be nested?
Difference between malloc() and calloc() function?
What is the value of uninitialized variable in c?
Why is structure padding done in c?
Given below are three different ways to print the character for ASCII code 88. Which is the correct way1) char c = 88; cout << c << " ";2) cout.put(88);3) cout << char(88) << " "; a) 1 b) 2 c) 3 d) constant
Difference between pass by reference and pass by value?
What are the data types present in c?
In C programming, how do you insert quote characters (‘ and “) into the output screen?
Why #include is used in c language?
What does 3 mean in texting?
What's the best way of making my program efficient?
Explain what is the difference between null and nul?
Where in memory are my variables stored?