/* CPSC 1011, Section 003, lab 6
   Mary-Grace Nelson
   3/3/23
Description: program reads poe_raven.txt 
file using redirection, saves it to an array, 
then prints it.
*/

//max lines printed
#define MAX_LINE 200

//max length of lines printed
#define MAX_LINE_LEN 100

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

int main() {
	char poe_try[MAX_LINE][MAX_LINE_LEN]; //2D array
	int row = 0, col = 0, i; 
	char a;


//read into poe-raven.txt file and store in poe_try array

	//read one character of input while not the end of the file
	while ((a = getchar()) != EOF) { 

		//if character equals end of line	
		if (a == '\n') {

			//stop line
			poe_try[row][col] = '\0';

			//jump to next row
			row++;

			//column set back to 0
			col = 0;                    
		}

		else {
			//save character to poe_try array
			poe_try[row][col++] = a;
		}
	}

//prints number of rows in txt file
        printf("\nThis poem has %d lines.\n\n", row);


//print characters in poe_try array

	//run through characters in forward direction
	for (i = 0; i < row; i++) {            
		printf("%s\n", poe_try[i]);
	}

	return 0;

}
