Answer to Question #17765 in C++ for apoorva
2012-11-02T09:01:22-04:00
Write a c++ function that compares two strings and returns 0 if the two strings are equal and -1 if the strings are unequal.
1
2012-11-02T13:02:56-0400
#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 !
Learn more about our help with Assignments:
C++
Comments
Leave a comment