64 542
Assignments Done
99,3%
Successfully Done
In September 2018

Answer to Question #17765 in C++ for apoorva

Question #17765
Write a c++ function that compares two strings and returns 0 if the two strings are equal and -1 if the strings are unequal.
Expert's answer

#include<stdio.h>

int compare_string(char*, char*);

int main()
{
char first[100], second[100], result;

printf("Enter first string
");
gets(first);

printf("Enter second string
");
gets(second);

result = compare_string(first, second);

if ( result == 0 )
printf("Both strings are same.
");
else
printf("Entered strings are not equal.
");

int k;
scanf("%d",&k);
return 0;
}

int compare_string(char *first, char *second)
{
while(*first==*second)
{
if ( *first == '' || *second == '' )
break;

first++;
second++;
}
if( *first == '' && *second == '' )
return 0;
else
return -1;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions