// computeSplitTime.cc
// P. Conrad 03/06/06
// separately compiled computeSplitTime() function

#include <cstring> // strtok
#include <cstdlib> // atoi and atof
using namespace std;

double computeSplitTime(const char *  const splitTimePtr)
{
  
  // first task... make a local copy of the input string
  // that we can work with

  // an idea we'll explore in a future version... compute
  //  the exact size we need for the local copy by doing
  
  // int sizeNeeded = strlen(splitTimePtr) + 1 ;  // + 1 for null term
  // and then allocate a local copy of the exact correct size.

  // for now, we'll just over-engineer it.

  char splitTimeCopy[1024]; // over-engineered in a big way

  // Later, come back and talk about strcpy vs. strncpy vs. strpcpy
  //  buffer overruns, hacking, security, etc...

  strcpy(splitTimeCopy, splitTimePtr);
  
  // now proceed with the rest of the function...

  double result;

  // stub function @@@ finish the stub later!!!

  // use strtok to divide the string into the first part
  // which is in minutes, and the second part which is in seconds.

  // for example, 1:51.9 will be divided into 1\051.9

  char *firstPart;
  char *secondPart;
  
  firstPart = strtok(splitTimeCopy,":");
  secondPart = strtok(NULL,":");

  // compute the result by converting firstPart to a number
  // and multiplying by 60, and add to second part
  // use atof on the second part, becuase it is a double
  // (yeah, go figure... there is no atod... atof returns not
  //    a float, but rather, a double)

  result = atoi(firstPart) * 60 + atof(secondPart);

  return result;
}









