/*
Alaina Thompson
CPSC 1011
Spring 2023
Section 003
This program can do four things. First: print the poem. Second:show the number of lines in the poem. Third: convert the case of the poem. Fourth: quit the program. It does this by using multiple 
loops and a switch statement.
*/

#include <stdio.h>
#include <string.h>

#define MAX_LINES 200
#define MAX_LINE_LEN 100

int main(void) {

	FILE *inFile = fopen("input.txt", "r"); 
	char theText[MAX_LINES][MAX_LINE_LEN];
	char oppositeCase[MAX_LINES][MAX_LINE_LEN];
	int numLines = 0;
	
	while (fgets(theText[numLines],MAX_LINE_LEN, inFile)) {
		numLines++;
		}
	
	for (int i=0; i < numLines; i++) {
		strcpy(oppositeCase[i], theText[i]);
		}

	int menuChoice = 0;

	//printed menu that is always displayed
	while (menuChoice != 4) {
		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", &menuChoice); 
		printf("\n"); 

		//switch statement that does all of the different options
		switch (menuChoice) {
		
			case 1:
				for (int i = 0; i < numLines; i++) {
					printf("%s", theText[i]);
					}
					break;
			case 2:
				printf("Number of lines: %d\n", numLines);
				break;
			case 3:
				for (int i = 0; i < numLines; i++) {
					for (int j = 0; j < strlen(oppositeCase[i]); j++) {
						if (oppositeCase[i][j] >= 'a' && oppositeCase[i][j] <= 'z') {
							oppositeCase[i][j] -= 32;
						} else if
						(oppositeCase[i][j] >= 'A' && oppositeCase[i][j] <= 'Z') {
													oppositeCase[i][j] += 32;
													}
											}
									}
						for (int i = 0; i < numLines; i++) {
							printf("%s", oppositeCase[i]);
										}
										break;
			case 4:
			break;
			default:
				printf("Invalid choice. Please enter 1, 2, 3, or 4.\n");
				}
				printf("\n");
			}

		fclose(inFile);

	return 0;
}

