(Comparing Strings) Write a program that uses function strcmp to compare two strings in- put by the user. The program should state whether the first string is less than, equal to or greater than the second string.
What will be an ideal response?
```
#include
#include
using namespace std;
const int SIZE = 20;
int main()
{
char string1[ SIZE ];
char string2[ SIZE ];
int result;
cout << "Enter two strings: ";
cin >> string1 >> string2;
// uses function strcmp to compare the two strings
result = strcmp( string1, string2 );
if ( result > 0 )
cout << '\"' << string1 << '\"' << " is greater than \""
<< string2 << '\"' << endl;
else if ( result == 0 )
cout << '\"' << string1 << '\"' << " is equal to \"" << string2
<< '\"' << endl;
else
cout << '\"' << string1 << '\"' << " is less than \"" << string2
<< '\"' << endl;
return 0; // indicates successful termination
} // end main
```
Enter two strings: green leaf
"green" is less than "leaf"
You might also like to view...
A(n) ________ album is a presentation composed of pictures
Fill in the blank(s) with correct word
What feature is used to fit a shape to the inserted picture?
A) Picture Border B) Picture Effects C) Crop to Shape D) Shape to Picture