/* hiking_s1.c  P. Conrad CISC105  Fall 2005 */
/* Example file for step1 of project 3 */

#include <stdio.h>
#include <string.h> /* for strtok, strncpy */
#include <stdlib.h> /* for atof() */

#include "hiking.h"

#define MAXLINE 1024 /* maximum length of input line in file */


/* function prototypes */

/* Ask about this "const" in lecture */

void   printValues(const struct Hiking_S * const hikingData); 



void setValuesToEmptyStringAndZero(struct Hiking_S *hikingData);
void anotherWayToSetValuesToEmptyStringAndZero(struct Hiking_S *hikingData);
void yetAnotherWayToSetValuesToEmptyStringAndZero(struct Hiking_S *hikingData);

/***************** MAIN PROGRAM **************/

int main(void)
{
  /* declare variables */

  struct Hiking_S hikingData;
  struct Hiking_S anotherTrail;


  /* now set the values in the struct */

  strncpy(hikingData.name,"South Kaibab",HIKING_TRAIL_NAME_LEN);
  strncpy(hikingData.location,"Grand Canyon NP",HIKING_TRAIL_LOCATION_LEN);
  hikingData.lengthInMiles = 9.2;
  strncpy(hikingData.state,"AZ",HIKING_TRAIL_STATE_LEN);
  hikingData.numTimesHiked = 1;

  /* print out the result */

  printf("***Here are the contents of hikingData after setting values***\n");
  printValues( &hikingData);

  /* set the values in another struct and print them */

  strncpy(anotherTrail.name,"North Kaibab",HIKING_TRAIL_NAME_LEN);
  strncpy(anotherTrail.location,"Grand Canyon NP",HIKING_TRAIL_LOCATION_LEN);
  anotherTrail.lengthInMiles = 16.0;
  strncpy(anotherTrail.state,"AZ",HIKING_TRAIL_STATE_LEN);
  anotherTrail.numTimesHiked = 0;

  printf("\n\n");
  printf("***Here are the contents of anotherTrail after setting values***\n");
  printValues( &anotherTrail);


  /* show function call that sets the contents to zero and empty */
 
  setValuesToEmptyStringAndZero( &hikingData);

  /* now print out the result */

  printf("\n\n");
  printf("***Here are the contents of hikingData after ***\n");
  printf("***a call to setValuesToEmptyStringAndZero ***\n");
  printValues( &hikingData);


  /* show function call that sets value to zero and empty a different way  */
 
  anotherWayToSetValuesToEmptyStringAndZero(&anotherTrail);

  /* now print out the result */

  printf("\n\n");
  printf("***Here are the contents of anotherTrail after ***\n");
  printf("***a call to anotherWayToSetValuesToEmptyStringAndZero ***\n");
  printValues( &anotherTrail);

  /* restore values in the struct another trail and print */

  strncpy(anotherTrail.name,"North Kaibab",HIKING_TRAIL_NAME_LEN);
  strncpy(anotherTrail.location,"Grand Canyon NP",HIKING_TRAIL_LOCATION_LEN);
  anotherTrail.lengthInMiles = 16.0;
  strncpy(anotherTrail.state,"AZ",HIKING_TRAIL_STATE_LEN);
  anotherTrail.numTimesHiked = 0;

  printf("\n\n");
  printf("***Here are the contents of anotherTrail after  ***\n");
  printf("*** the values were restored                    ***\n");
  printValues( &anotherTrail);
  

  /* zero out those values one additional way and then print */

  yetAnotherWayToSetValuesToEmptyStringAndZero(&anotherTrail);

  printf("\n\n");
  printf("***Here are the contents of anotherTrail after  ***\n");
  printf("*** a call to yetAnotherWayToSetValuesToEmptyStringAndZero ***\n");
  printValues( &anotherTrail);


  return 0;

}


void printValues(const struct Hiking_S * const hikingData)
{

  printf("Name of trail    : %s\n", (*hikingData).name);
  printf("Location of trail: %s\n", (*hikingData).location );
  printf("State            : %s\n", (*hikingData).state);
  printf("Length in miles  : %6.1lf\n", (*hikingData).lengthInMiles );

  if ((*hikingData).numTimesHiked == 0) /* const helps me avoid = vs. == mistake */
    printf("Num times hiked  : never\n");
  else
    printf("Num times hiked  : %d\n", (*hikingData).numTimesHiked);

}

void  setValuesToEmptyStringAndZero(struct Hiking_S *hikingData)
{
  (*hikingData).name[0] = '\0';
  (*hikingData).location[0] = '\0';
  (*hikingData).lengthInMiles = 0.0;
  (*hikingData).state[0] = '\0';
  (*hikingData).numTimesHiked = 0;
}


void anotherWayToSetValuesToEmptyStringAndZero(struct Hiking_S *hikingData)
{
  hikingData->name[0] = '\0';
  hikingData->location[0] = '\0';
  hikingData->lengthInMiles = 0.0;
  hikingData->state[0] = '\0';
  hikingData->numTimesHiked = 0;
}

void yetAnotherWayToSetValuesToEmptyStringAndZero(struct Hiking_S *hikingData)
{
  hikingData[0].name[0] = '\0';
  hikingData[0].location[0] = '\0';
  hikingData[0].lengthInMiles = 0.0;
  hikingData[0].state[0] = '\0';
  hikingData[0].numTimesHiked = 0;
}










