[i]#include <iostream>

#include <cstring>   // required for the string function library

using namespace std;

 

int main()

{

  const int MAXELS = 50;

  char string1[MAXELS];

  char string2[MAXELS];

  int n;

 

      strcpy(string1, "cat");

      strcpy(string2, "catdog");

 

      n = strcmp(string1, string2);

 

      cout << "string 1\t\tstring2\t\tn" << endl;

      cout << "-----------------------------------------------------" << endl;

      cout << string1 << "\t\t\t" << string2 << "\t\t" << n<< endl;

 

      strcpy(string1, "hello");

      strcpy(string2, "hello ");

 

      n = strcmp(string1, string2);

 

      cout << string1 << "\t\t\t" << string2 << "\t\t" << n<< endl;

 

      strcpy(string1, "hello");

      strcpy(string2, "hello");

 

      n = strcmp(string1, string2);

 

      cout << string1 << "\t\t\t" << string2 << "\t\t" << n<< endl;

 

 

      strcpy(string1, "123");

      strcpy(string2, "12277");

 

      n = strcmp(string1, string2);

 

      cout << string1 << "\t\t\t" << string2 << "\t\t" << n<< endl;

     

      strcpy(string1, "Spain");

      strcpy(string2, "spain");

 

      n = strcmp(string1, string2);

 

      cout << string1 << "\t\t\t" << string2 << "\t\t" << n<< endl;

 

      strcpy(string1, "123");

      strcpy(string2, "aaa");

 

      n = strcmp(string1, string2);

 

      cout << string1 << "\t\t\t" << string2 << "\t\t" << n<< endl<<endl;

 

      return 0;

}

 

/*


 

string 1                string2         n

-----------------------------------------------------

cat                     catdog          -1

hello                   hello           -1

hello                   hello           0

123                     12277           1

Spain                   spain           -1

123                     aaa             -1

 

Press any key to continue

*/

 



[i] These examples were created by Professor Imberman