1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
|
#include <fstream>
#include <iomanip>
#include <iostream>
using namespace std;
void readPuzzle(ifstream, int, int, char, char, int &, int &);
void printPuzzle(puzzleInfo);
const int MAX_ROWS = 20;
const int MAX_COLUMNS = 20;
const int MAX_WORD_COUNT = 25;
const int MAX_WORD_LENGTH = 32;
struct puzzleInfo
{
int mRows;
int mColumns;
char mPuzzle [MAX_ROWS][MAX_COLUMNS];
char mWords [MAX_WORD_COUNT][MAX_WORD_LENGTH];
};
int main()
{
ifstream inputFile;
puzzleInfo sRows, sColumns, sPuzzle, sWords;
printPuzzle(sPuzzle);
return EXIT_SUCCESS;
}
void readPuzzle(ifstream inputFile, puzzleInfo sRows, puzzleInfo sColumns,
puzzleInfo sPuzzle, puzzleInfo sWords, int &row, int &column)
{
int count = 0;
int counter = 0;
inputFile.open("puzzle.txt");
if(inputFile.fail())
{
cout << "Error: failure to open file." << endl;
}
inputFile >> row;
inputFile >> column;
inputFile.peek();
while(!inputFile.eof() && count < row)
{
inputFile.getline(sPuzzle.mPuzzle[count], MAX_COLUMNS);
inputFile.get();
count++;
}
while(!inputFile.eof() && counter < MAX_WORD_COUNT)
{
inputFile.getline(sPuzzle.mWords[counter], MAX_WORD_LENGTH);
inputFile.get();
counter++;
}
}
void printPuzzle(puzzleInfo sPuzzle)
{
cout << "*****************************\n";
cout << "* Find A Word *\n";
cout << "*****************************\n\n";
cout << "Number of Rows: " << endl;
cout << "Number of Columns: " << endl << endl;
cout << "Puzzle\n";
cout << "------\n\n";
for (int i = 0; i < MAX_ROWS; i++)
{
cout << sPuzzle.mPuzzle[i];
}
cout << "Words\n";
cout << "-----\n\n";
for (int j = 0; j < MAX_WORD_COUNT; j++)
{
cout << sPuzzle.mWords[j];
}
}
|