/* pizza_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 "pizza.h"

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


/* function prototypes */

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

void   printValues(const struct PizzaOrder_S * const pizzaData); 



void setValuesToEmptyStringAndZero(struct PizzaOrder_S *pizzaData);
void anotherWayToSetValuesToEmptyStringAndZero(struct PizzaOrder_S *pizzaData);
void yetAnotherWayToSetValuesToEmptyStringAndZero(struct PizzaOrder_S *pizzaData);

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

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

  struct PizzaOrder_S pizzaData;
  struct PizzaOrder_S anotherOrder;


  /* now set the values in the struct */

  strncpy(pizzaData.topping,"cheese",PIZZA_TOPPING_NAME_LEN);
  strncpy(pizzaData.saladDressing,"ranch",SALAD_DRESSING_NAME_LEN);
  pizzaData.price = 9.99;
  pizzaData.numPizzas = 2;

  /* print out the result */

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

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

  strncpy(anotherOrder.topping,"Mushroom",PIZZA_TOPPING_NAME_LEN);
  strncpy(anotherOrder.saladDressing,"Creamy Italian",SALAD_DRESSING_NAME_LEN);
  anotherOrder.price = 7.99;
  anotherOrder.numPizzas = 1;

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


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

  /* now print out the result */

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


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

  /* now print out the result */

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

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

  strncpy(anotherOrder.topping,"Pepperoni",PIZZA_TOPPING_NAME_LEN);
  strncpy(anotherOrder.saladDressing,"Blue Cheese",SALAD_DRESSING_NAME_LEN);
  anotherOrder.price = 9.99;
  anotherOrder.numPizzas = 1;

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

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

  yetAnotherWayToSetValuesToEmptyStringAndZero(&anotherOrder);

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


  return 0;

}


void printValues(const struct PizzaOrder_S * const pizzaData)
{

  printf("Pizza topping      : %s\n", (*pizzaData).topping);
  printf("Salad dressing     : %s\n", (*pizzaData).saladDressing );
  printf("Price              : $%6.2lf\n", (*pizzaData).price );
  printf("Number of pizzas   : %d\n", (*pizzaData).numPizzas);

}

void  setValuesToEmptyStringAndZero(struct PizzaOrder_S *pizzaData)
{
  (*pizzaData).topping[0] = '\0';
  (*pizzaData).saladDressing[0] = '\0';
  (*pizzaData).price = 0.0;
  (*pizzaData).numPizzas = 0;
}


void anotherWayToSetValuesToEmptyStringAndZero(struct PizzaOrder_S *pizzaData)
{
  pizzaData->topping[0] = '\0';
  pizzaData->saladDressing[0] = '\0';
  pizzaData->price = 0.0;
  pizzaData->numPizzas = 0;
}

void yetAnotherWayToSetValuesToEmptyStringAndZero(struct PizzaOrder_S *pizzaData)
{
  pizzaData[0].topping[0] = '\0';
  pizzaData[0].saladDressing[0] = '\0';
  pizzaData[0].price = 0.0;
  pizzaData[0].numPizzas = 0;
}










