
// reading a text file
#define WIDTH 10
#define HEIGHT 9
#include <iostream>
#include <fstream>
#include <string>
using namespace std;

int main(void) {
	char text[WIDTH * HEIGHT];
	string line;
	ifstream myfile("text.txt");
	if (myfile.is_open())
	{
		int count = 0;
		while (getline(myfile, line))
		{
			cout << line << endl;


			line.copy(&text[WIDTH * count], WIDTH, 0);
			count++;
		}
		myfile.close();
	}
	else cout << "Unable to open file";

	cout << endl << endl << endl;

	for (int y = 0; y < HEIGHT; y++)
	{
		for (int x = 0; x < WIDTH; x++)
		{
			cout << text[WIDTH * y + x];
		}
		cout << endl;
	}

	//OUTPUT letter 'U' to screen
	int x=5, y=3;
	cout << text[WIDTH * y + x]<<endl;

	//given (x,y) is (5,6)  OUTPUT the char (1) AND the chars above (0), below it (-), left (3) and right (4) of it 
	x = 5;
	y = 6;
	cout <<"current position centered on ( "<<x<<" , "<<y<<")"<< "char is: "<<text[WIDTH * y + x]<<endl;
	cout << "above char is: " << text[WIDTH * (y - 1) + x] << endl;
	cout << "below char is: " << text[WIDTH * (y + 1) + x] << endl;
	cout << "left char is: " << text[WIDTH * (y) + (x-1)] << endl;
	cout << "right char is: " << text[WIDTH * (y) + (x+1)] << endl;
	return 0;
}