/*	Andres Perez
	CPSC 1010 Spring 2023
	Lab 004
	This program reads from an inputed text file and prompts the user with a menu of options.
	The progam then takes input from the user and selects one of the priorly stated options,
	the options being: prining the inputed text file, reading the amount of lines, 
	convertinf the cases of the text file, and quiting the application.
*/


#include <stdio.h>

const int lineCap = 200;
int charCap = 100;

int printMenu() {

	int menu;

	printf("\nChoose from the menu:\n"); 
	printf("\t1. print the poem\n"); 
	printf("\t2. show number of lines in the poem\n"); 
	printf("\t3. convert the case\n"); 
	printf("\t4. quit\n\n"); 
	printf("\t - - > "); 
	scanf("%d", &menu);
	printf("\n");

	return menu;

}


void printArray(char poemArray [lineCap] [charCap], int txtLine) {
	
	int c;

	for (c = 0; c < txtLine; c++) {
	
		printf (" %s", poemArray[c]);
	
	}
}




void convertCase (char poemArray[lineCap] [charCap]) {


	int c, column, row;
	char caseSwitch[lineCap] [charCap];

			for (row = 0; row < lineCap; row++) {
				for (column = 0; column < charCap; column++) {
					
					if((poemArray[row][column] <= 90) && (poemArray[row][column] >= 65)) {
						caseSwitch[row][column] = poemArray[row][column] + 32;
					}
					else if((poemArray[row][column] >= 97) && (poemArray [row][column] <=122)) {
						caseSwitch[row][column] = poemArray[row][column] - 32;
					}
					else{
						caseSwitch[row][column] = poemArray[row][column];
					}

				}
			


			}	
			for (c = 0; c < 145; c++) {
				printf(" %s", caseSwitch[c]);
			}
}

int main(void) {

	//const int lineCap = 200;
	//int charCap = 100;
	char poemArray[lineCap] [charCap];
	//int c, column, row;
	int txtLine = 0;
	int menuChoice = 0;
	int loop1 = 0;
	//char caseSwitch[lineCap] [charCap];
	FILE *inFile = fopen("input.txt", "r"); 

	while (fgets(poemArray[txtLine], lineCap, inFile))	{
		txtLine++;
	}	


	while (loop1 == 0) {

		menuChoice = printMenu();

		if (menuChoice == 2) {
			printf ("The poem has %d lines.\n", txtLine);
			}
		if (menuChoice == 1) {
				printArray(poemArray, txtLine);
		}
		if (menuChoice == 4) {
			loop1 = 1;
		}
		if (menuChoice == 3) {

			convertCase (poemArray);
		}
	}
}

