//Programmer: Bo Bayles  Date: 2 November 2004
//File: copyStrings.cpp        Class: CS54 C
//Purpose: This program recreates the functionality of the strcpy function
//  and makes sure the arrays are in the correct bounds.

#include <iostream>
using namespace std;

void mystrcpy(char dest[], char source[], int destSize);

int main()
{
  char source[20];
  char dest[15];

  cout << "Enter the first string: ";
  cin >> source;

  cout << "Enter the second string: ";
  cin >> dest;

  cout << endl << "The first string was: " << source << endl
       << "The second string was: " << dest << endl;

  mystrcpy(dest, source, 15);

  cout << "The second string is now: " << dest << endl;

  return 0;
}

void mystrcpy(char dest[], char source[], int destSize)
{
  int sourceSize = 0;
  int i = 0;

  while(source[sourceSize] != '\0')
    sourceSize++;

  if (sourceSize < destSize)
  {
  for (i = 0; i < destSize; i++)
    dest[i] = source[i];
  }
  else
    cout << endl << "The source is too large." << endl;

  dest[i+1] = '\0';

  return;
}
//Count the number of characters that aren't null in the source,
//  then make sure that number is smaller than the size of the
//  destination. If it's not, copy each non-null char in the source to the
//  destination. Then add a null to the end of the destination.

