/* Eli Boccolucci
   07 March 2023
   Lab Section: 001
   Lab 7 
   Takes an arrary and puts the contents into another array. Using do, while, and for loops.
*/

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

int main (void){

	FILE *inFile = fopen("input.txt", "r");
        const int MAX_LINE = 200;
        const int MAX_LINE_LEN = 100;
        char lab6[MAX_LINE][MAX_LINE_LEN];
        int i = 0 ,num_of_lines = 0, j =0, num = 0;
	char oppositeCase[MAX_LINE][MAX_LINE_LEN];
	int menuChoice;

	while((fgets(lab6[i], MAX_LINE_LEN, inFile) != NULL))
        {
                i++;
        }
	num_of_lines = i;

	do{
	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(lab6[i], MAX_LINE_LEN, inFile) != NULL))
        {
                i++;
        }
        num_of_lines = i;
        for (i = 0; i < num_of_lines; i++)
        {
                        printf ("%s", lab6[i]);
        }
	
	} 
	else if (menuChoice == 2) {
                while((fgets(lab6[i], MAX_LINE_LEN, inFile) != NULL))
        {
                i++;
        }
	num_of_lines = i;
        printf("The poem has %d lines.\n",num_of_lines);

        } 
	else if (menuChoice == 3) {
                for(i = 0; i < num_of_lines; i++) {	
			strcpy(oppositeCase[i], lab6[i]);
			for(j = 0; j < (int)strlen(oppositeCase[i]); j++) {
				if(oppositeCase[i][j] >= 97 && oppositeCase[i][j] <= 122){ 
        				oppositeCase[i][j] -= 32;
				}else if(oppositeCase[i][j] >= 65 && oppositeCase[i][j] <= 90){
			       		oppositeCase [i][j] += 32;
					}
			}
			printf("%s", oppositeCase[i]);	
		}
        } 
	else if (menuChoice == 4) {
		break;
	}
	}while(num == 0); 
	        
	fclose(inFile);
        return 0;
}
