I have been pondering on this assignment for 4 days now and still have not figured out the best way around doing it, I've thought of a few useless ideas that will probably be extremely complicated and a few hundred thousand lines long, but nothing that really logically makes sense.
The assignment requires firstly to have an input file which contains functions 'size=' and 'searchfor=' then a puzzle, additionally it can contain blank whitespace lines as comments, or lines containing hash and everything after that being a comment. we must have a search= and size= before we can process the puzzle, if these are not found then I should output an error.
Once the input has been validated secondly we are to create the puzzle dynamically using only char arrays and not using string or cstring classes, output the results delete the array and move onto the next puzzle/validation.
For validation I figured I could do something like:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
|
string line, word, size="size=", searchfor="searchfor=";
bool gotSize=false, gotWord=false;
ifstream ifs;
size_t found;
// etc....
while (!ifs.eof())
{
getline(ifs,line);
if (found=line.find(size))
{
gotSize=true;
// etc ...
}
else if (found=line.find(searchfor))
{
gotWord=true;
....// etc
|
assuming that will work, might have to do a whole heap of found declarations and then check or something... will this work Or is there perhaps a better logic I can use?
But as for the trying to solve the puzzle, I was thinking maybe I could search for the first letter once found I need to look for the rest of the word in every direction, searching for the next letter won't work I have thought of that and then I would need to keep track of too many things, I think what I need to do is A. search for the first letter once found, check the directions, west, northwest, north, northeast, east, southeast, south, southwest. and for each if found perhaps place in a duplicate array that is full of nulls, in the same positioning. The output needs to look something like the following.
size=9,4
searchfor=word
puzzle:
1 2 3 4
|
wordrowoc
cokqdomoo
bxrprjhar
ntydrow&s
|
solved:
1 2 3 4
|
wordrow..
.o...o...
..r.r....
...drow..
|