//***************************************
//sort3cstrings.cpp
//R. A. Hillyard
//
// Program to sort 3 cstrings
// Shows use of cstring functions
// included in the cstring and cstdlib library
//***************************************

#include<iostream>
#include<cstring>
#include<cstdlib>
using namespace std;

void sort3(char a[], char b[], char c[]);
void swap(char a[], char b[]);

const int BufSize = 20;

int main()
  {
  char a[BufSize];
  char b[BufSize];
  char c[BufSize];
  
  cout << "Enter three strings (on the same line)\n> ";
  cin >> a >> b >> c;
  sort3(a,b,c);
  cout << "\nsorted: " << a << " " << b << " " << c << endl;
  return 0;
  }//end main

/*************************************************************/
void sort3(char a[], char b[], char c[])
  {
  if(strcmp(a,b) > 0)
    {
    swap(a,b);
    }
  if(strcmp(a,c) > 0)
    {
    swap(a,c);
    }
  if(strcmp(b,c) > 0)
    {
    swap(b,c);
    }
  }//end sort3

/*************************************************************/
void swap(char a[], char b[])
  {
  char temp[BufSize];
  strcpy(temp, a);
  strcpy(a, b);
  strcpy(b, temp);
  }//end swap
/*************************************************************/

/*****************Program output******************************/
Enter three strings (on the same line)
> last middle first

sorted: first last middle

Enter three strings (on the same line)
> why only 3

sorted: 3 only why

Enter three strings (on the same line)
> have a cow

sorted: a cow have