// Quinn Sullivan
// 03/14/2023
// Section 004
// Lab 8
// Scanning The Raven and copying into a different file, declare a file pointer, reading in the text, and counting the characters. 
#include <stdio.h>
#include <string.h>

#define MAX_LINE 200
#define MAX_LINE_LEN 100


int printMenu();
void printArray(char text[MAX_LINE][MAX_LINE_LEN], int size);
void convertCase(char text[MAX_LINE][MAX_LINE_LEN]);

int main(void){
        FILE *inFile = fopen("input.txt", "r");
        char poem[MAX_LINE][MAX_LINE_LEN];
        int i = 0;
	int f = 0;
        int menuChoice = 0;
	int numlines = 0;
        char oppositeCase[MAX_LINE][MAX_LINE_LEN];

        while(fgets(poem[i],MAX_LINE_LEN,inFile)){
                i++;
        }
	for(f = 0; f <= i ; f++){
		strcpy(oppositeCase[f], poem[f]);
	}

		numlines = i;
        while(menuChoice != 4){
                menuChoice = printMenu();
                if(menuChoice == 1){
                        printArray(poem,numlines);
                }
                else if(menuChoice == 2){
                        printf("The poem has %d lines.\n",numlines);
                }
                else if(menuChoice == 3){
                        convertCase(oppositeCase);
                	printArray(oppositeCase,numlines);      
        	}   
	}    
}

int printMenu(){
        int menuChoice;

        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");
        return(menuChoice);
}

void printArray(char text[MAX_LINE][MAX_LINE_LEN], int size){
        for(int k = 0; k < size; k++){          
                printf("%s",text[k]);
        }
}

void convertCase(char text[MAX_LINE][MAX_LINE_LEN]){
	for(int a = 0; a < MAX_LINE; a++){
                for(int b = 0; b < MAX_LINE_LEN; b++){
                        if((text[a][b] >= 65)&&(text[a][b] <= 90)){
                                text[a][b] += 32;
                        }
                        else if((text[a][b] >= 97)&&(text[a][b] <= 122)){
                                text[a][b] -= 32;
                        }
                        else{
                                text[a][b] = text[a][b];
                        }
                }
        }
}

