/* 
Matthew Kingswood
March 31st 2023
CPSC Lab 1011 Section 003 
Lab 9
File from lab9 that holds all of the Functions and code to run the program.
*/


#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++){
		fscanf(inFile, "%s", workout[i].name);
		fscanf(inFile, "%s", workout[i].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[]) {
	char checkH[20] = "hip_thrust", checkR[20] = "russian_twists";
	char checkL[20] = "leg_raises", checkS[20] = "situps/crunches";
	int check1, check2, check3, check4;
	for (int j=0; j < arraySize; j++) {
		check1=1,check2=1,check3=1,check4=1;
		printf("\n%s for %s:\n", workout[j].name, workout[j].muscles);
		check1 = strcmp(checkH, workout[j].name);
		check2 = strcmp(checkR, workout[j].name);
		check3 = strcmp(checkL, workout[j].name);
		check4 = strcmp(checkS, workout[j].name);
		if (check1==0) {
			printf("	Weight: ");
			scanf("%d", &workout[j].weight);
			printf("\n	Time: ");
			scanf("%d", &workout[j].time);
			printf("\n	Sets: ");
			scanf("%d", &workout[j].sets);
			printf("\n	Reps: ");
			scanf("%d", &workout[j].reps);
		} else if (check2==0) {
			printf("	Weight: ");
			scanf("%d", &workout[j].weight);
			printf("\n	Time: ");
			scanf("%d", &workout[j].time);
			printf("\n	Sets: ");
			scanf("%d", &workout[j].sets);
			printf("\n	Reps: ");
			scanf("%d", &workout[j].reps);
		} else if (check3==0) {
			printf("\n	Time: ");
			scanf("%d", &workout[j].time);
			printf("\n	Sets: ");
			scanf("%d", &workout[j].sets);
			printf("\n	Reps: ");
			scanf("%d", &workout[j].reps);
		} else if (check4==0) {
			printf("\n	Time: ");
			scanf("%d", &workout[j].time);
			printf("\n	Sets: ");
			scanf("%d", &workout[j].sets);
			printf("\n	Reps: ");
			scanf("%d", &workout[j].reps);
		} else {
			printf("\n	Weight: ");
			scanf("%d", &workout[j].weight);
			printf("\n	Sets: ");
			scanf("%d", &workout[j].sets);
			printf("\n	Reps: ");
			scanf("%d", &workout[j].reps);
		}
	}
}

