/* initArray() function will initialize the array of 
	exercises by reading them in from the file pointer 
	sent in as a parameter

	printArray() function will print the values 
	of the exercise items that are in the workout array 
	sent in as a parameter

	getWorkout() function will allow user to enter values
	for each exercise and put those into the array
*/


#include "defs.h"


// initializes the array
// inputs:  the size of the array, the array, and file pointer
// output:  none
void initArray(int arraySize, exercise workout[], FILE *inFile) {
	int i;
	for (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[]) {
	int i, value;
	// freopen("/dev/tty", "rw", stdin);
	for (i = 0; i < arraySize; i++) {
		printf("\n%s for %s:", workout[i].name, workout[i].muscles);
		if ( (strcmp(workout[i].name, "leg_raises") != 0) && (strcmp(workout[i].name, "situps/crunches") != 0) ) {
			printf("\n\tWeight: ");
			scanf("%d", &value);
			printf("\n");
			workout[i].weight = value;
		}
		else
			printf("\n");
		if ( (strcmp(workout[i].name, "hip_thrust") == 0) || (strcmp(workout[i].name, "russian_twists") == 0) || (strcmp(workout[i].name, "leg_raises") == 0) || (strcmp(workout[i].name, "situps/crunches") == 0) ) {
			printf("\tTime: ");
			scanf("%d", &value);
			printf("\n");
			workout[i].time = value;
		}
		printf("\tSets: ");
		scanf("%d", &value);
		printf("\n");
		workout[i].sets = value;
		printf("\tReps: ");
		scanf("%d", &value);
		printf("\n");
		workout[i].reps = value;
		printf("\n");
	}	
}

