/* Drew Labrador
	CPSC 1010, Spring Semester
	Lab #9 - Structs
	This file contains all the main functions of the lab9.c file.
 */


#include "defs.h"


// initializes the array of exercises
// inputs:  the size of the array, the array, and file pointer
// output:  none
void initArray(int arraySize, exercise workout[], FILE * inFile) {
	for (int i = 0; i < arraySize; i++) {
		workout[i].weight = 0;
		workout[i].time = 0;
		workout[i].sets = 0;
		workout[i].reps = 0;
	}



	for (int i = 0; i < arraySize; i++) {
		fscanf(inFile, "%s %s", &workout[i].name[0], &workout[i].muscles[0]);
	}
}


// prints the array
// inputs:  the size of the array and the array
// output:  none
void printArray(int arraySize, exercise workout[]) {
	int i;
	printf("\n%-25s %-36s %5s %5s %5s %5s\n", 
			"EXERCISE", "MUSCLES", "WEIGHT",
			"TIME", "SETS", "REPS");
	for (i = 0; i < arraySize; i++) {
		printf("%2d. %-21s %-35s %5d %5d %5d %5d\n", 
				i+1,
				workout[i].name,
				workout[i].muscles,
				workout[i].weight,
				workout[i].time,
				workout[i].sets,
				workout[i].reps);
	}
	printf("\n");
}


// fills in the array with the values from the user to create
//		their workout plan
// note the call to freopen which sets the stdin back to the terminal
// inputs:  the size of the array and the array
// output:  none
void getWorkout(int arraySize, exercise workout[]) {

	int input;

	for (int i = 0; i < arraySize; i++) {
		if (strcmp(workout[i].name, "leg_raises") == 0) {
			printf("\n%s for %s:\n", workout[i].name, workout[i].muscles); 

			workout[i].weight = 0;

			printf("	Time: ");
			scanf("%d", &input);
			workout[i].time = input;

			printf("	Sets: ");
			scanf("%d", &input);
			workout[i].sets = input;

			printf("	Reps: ");
			scanf("%d", &input);
			workout[i].reps = input;
		}
		else if (strcmp(workout[i].name, "situps/crunches") == 0) {
			printf("\n%s for %s:\n", workout[i].name, workout[i].muscles);

			workout[i].weight = 0;

			printf("	Time: ");
			scanf("%d", &input);
			workout[i].time = input;

			printf("	Sets: ");
			scanf("%d", &input);
			workout[i].sets = input;

			printf("	Reps: ");
			scanf("%d", &input);
			workout[i].reps = input;
		}
		else if (strcmp(workout[i].name, "hip_thrust") == 0) {
			printf("\n%s for %s:\n", workout[i].name, workout[i].muscles);

			printf("	Weight: ");
			scanf("%d", &input);
			workout[i].weight = input;

			printf("	Time: ");
			scanf("%d", &input);
			workout[i].time = input;

			printf("	Sets: ");
			scanf("%d", &input);
			workout[i].sets = input;

			printf("	Reps: ");
			scanf("%d", &input);
			workout[i].reps = input;
		}
		else if (strcmp(workout[i].name, "russian_twists") == 0) {
			printf("\n%s for %s:\n", workout[i].name, workout[i].muscles);

			printf("	Weight: ");
			scanf("%d", &input);
			workout[i].weight = input;

			printf("	Time: ");
			scanf("%d", &input);
			workout[i].time = input;

			printf("	Sets: ");
			scanf("%d", &input);
			workout[i].sets = input;

			printf("	Reps: ");
			scanf("%d", &input);
			workout[i].reps = input;
		}
		else {
			printf("\n%s for %s:\n", workout[i].name, workout[i].muscles);

			workout[i].time = 0;

			printf("	Weight: ");
			scanf("%d", &input);
			workout[i].weight = input;

			printf("	Sets: ");
			scanf("%d", &input);
			workout[i].sets = input;

			printf("	Reps: ");
			scanf("%d", &input);
			workout[i].reps = input;
		}


	}









}

