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
Explain about block scope in c?
What is c definition?
Explain output of printf("Hello World"-'A'+'B'); ?
int i[2], j; int *pi;i[0] = 1; i[1] = 5; pi = i; j = *pi + 1 + *(pi + 1)Value of j after execution of the above statements will be a) 7 b) 6 c) 4 d) pointer
Explain how do you sort filenames in a directory?
Explain that why C is procedural?
What are the advantages and disadvantages of pointers?
How can I insert or delete a line (or record) in the middle of a file?
What is putchar() function?
What is the significance of an algorithm to C programming?
.main() { char *p = "hello world!"; p[0] = 'H'; printf("%s",p); }
Are local variables initialized to zero by default in c?
Is there anything like an ifdef for typedefs?
how to build a exercise findig min number of e heap with list imlemented?
What's the total generic pointer type?