/*
Haylee Smith
3/10/2023
CPSC 1010 Lab Section 004, Spring 2023
Lab #7
This program allows the user to choice to print the poem, see the number
of lines in the poem, or convert the case of the porm, and quit when done.
*/

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

int main (){
	const int MAX_LINE = 200;
	const int MAX_LINE_LEN = 100;
	int i, j, c, r, l, menuChoice;
	FILE *inFile = fopen("input.txt", "r");

	char poem[MAX_LINE][MAX_LINE_LEN];
	i = 0;

	char oppositeCase[MAX_LINE][MAX_LINE_LEN];
	c = 0;
	
	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");

		if (menuChoice == 1){
			while (fgets(poem[i], MAX_LINE_LEN, inFile)) {
         	i += 1;
      	}	
			for (j = 0; j < i; j++){
				puts(poem[j]);
			}
		}

		else if (menuChoice == 2){
      	while (fgets(poem[i], MAX_LINE_LEN, inFile)) {
         	i += 1;
      	}
			printf("This poem has %d lines.\n", i);
		}

		else if (menuChoice == 3){
			while (fgets(oppositeCase[c], MAX_LINE_LEN, inFile)) {
				c += 1;
         }

         for (r = 0; r < c; r++){
				for (l = 0; l <= strlen(oppositeCase[r]); l++){
					if (oppositeCase[r][l] >= 65 && oppositeCase[r][l] <= 90){
						oppositeCase[r][l] = oppositeCase[r][l] + 32;
					}
					else if (oppositeCase[r][l] >= 97 && oppositeCase[r][l] <= 122){
						oppositeCase[r][l] = oppositeCase[r][l] - 32;
					}
				}
				puts(oppositeCase[r]);
			}
		}
	}
	return 0;
}
