/* 
	Kaylee Pierce
	03/28/2023
	CPSC 1011-002
	Lab 9
	This file contains the initArray, printArray,
	and getWorkout functions that are used in main
*/


#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++) {
		char name[NAME_LENGTH];
		char muscles[MUSCLES_LENGTH];
		fscanf(inFile, "%s %s", name, muscles);

		strcpy(workout[i].name, name);
		strcpy(workout[i].muscles, muscles);
		workout[i].weight = 0;
		workout[i].time = 0;
		workout[i].sets = 0;
		workout[i].reps = 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[]) {
	for(int i = 0; i < arraySize; i++) {
		printf("\n%s for %s:\n", workout[i].name, workout[i].muscles);
		if(strcmp(workout[i].name, "bench_press") == 0 || strcmp(workout[i].name, "squat") == 0 ||
			strcmp(workout[i].name, "dead_lift") == 0 || strcmp(workout[i].name, "power_clean") == 0 ||
			strcmp(workout[i].name, "bicep_curls") == 0 || strcmp(workout[i].name, "tricep_pulldowns") == 0 ||
			strcmp(workout[i].name, "tricep_kickbacks") == 0){
				printf("Weight: ");
				scanf("%d", &workout[i].weight);
				printf("\n");
				printf("Sets: ");
				scanf("%d", &workout[i].sets);
				printf("\n");
				printf("Reps: ");
				scanf("%d", &workout[i].reps);
				printf("\n");
		} else if(strcmp(workout[i].name, "hip_thrust") == 0 || strcmp(workout[i].name, "russian_twists") == 0){
			printf("Weight: ");
			scanf("%d", &workout[i].weight);
			printf("\n");
			printf("Time: ");
			scanf("%d", &workout[i].time);
			printf("\n");
			printf("Sets: ");
			scanf("%d", &workout[i].sets);
			printf("\n");
			printf("Reps: ");
			scanf("%d", &workout[i].reps);
			printf("\n");
		} else if(strcmp(workout[i].name, "leg_raises") == 0 || strcmp(workout[i].name, "situps/crunches") == 0){
			printf("Time: ");
			scanf("%d", &workout[i].time);
			printf("\n");
			printf("Sets: ");
			scanf("%d", &workout[i].sets);
			printf("\n");
			printf("Reps: ");
			scanf("%d", &workout[i].reps);
			printf("\n");
		}
	}	
	printf("\n");
}
