I need to make a word search program that takes in a txt file like this
M J N W B X H S J P L W P I J
U T G U I A C L A E Z E D F B
J J K Z J J L Y T X E T M D W
F U N C T I O N A L P Z L V W
T G S C R U M A J O V H A G L
A J Z I E S U U I S Q Z N A I
Z N A T W Q Z L D H Z L D W Q
E H A H B I H K I O U Y E J G
D Z H G T J L J Q B G F R Z Q
U E A E K Y B L F I E H T D S
X V M G V W Y F I X C U L D J
F S D G F X Z L C N M R G L M
D P F Z R N K U T G G D S U S
K G I T M P S O L L T G A Z N
W R U B T E W T R T V R Z U A
EXCUSE
FUNCTIONAL
GOD
LANDER
TEXT
WILLING
and finds the word and outputs their position in another file
Any ideas on how I would do this?
Well, you can start by reading in the file into a 2D array, and then looking for the start letters of every word in each cell,,, and then searching in all directions for the next letter in the word, etc.
You're not doing your file I/O correctly. really, you're better off having initialize() taking a string with the file name: void initialize(constchar* filename)
then you can call it as: void initialize("wordsearch_data.txt")
and inside you can open, read, and close the file.
You need to use the extraction operator on your stream when reading from file: inputFile >> table[i][j];.
Also, it doesn't make any sense to insert inputFile on cout like you do in line 29. It should be just cout << table[i][j]];
For formatting you can print a space between the characters, and in the outer for loop you should print a newline.
Finally, remove all the other fstream variables you have, just declare the fstream object locally in Initialize(). After you've read in the input, you don't need the file anymore.
Thanks that helped me get it working, now that I got that I am trying to get the words within the array, any idea on what I am doing wrong? When it outputs the words it just outputs letters.
The reason you aren't reading in your words correctly is because when you re-open the file in wordcheck(), you start at the beginning of the file again, and you would have to read and discard the whole grid of letters before reading your words.
If you pass in a file stream by reference which is already open, once you read in the grid of letters you can then continue reading the words.
Thank you so much for your help. I am trying to check the array for the words now but every time I run it the program crashes. I used the return statements as just a quick reference to see if it was working.