-
WordSquare Problem Pt 1
I have been given a project concerning a wordsquare.
One part of the assignment is displaying the wordsquare (2d array).
I understand i need to read in a file.
My 1st question is, do i need to store the file that i have read in anywhere so i can display it?
My 2nd question is, how do i display the wordsquare.
I am using Vim for writing code and Terminal for compiling code if this helps.
Thanks in advance.
-
James, you need to provide a bit more information. What is in your input file? What should the output look like? What is a wordsquare?
Sure you need to store your file input into something if you plan to do some processing on it.
-
A word square is essentially like a grid of rows and columns with letters in them. People are then asked to find words in the word square that match up to a list of words given. You usually find them in papers, or when you were younger in like a spelling book.
My input is a sample grid-file containing letters. Its a 7 x 12 if that helps. My other input is a sample word-file containing the list of words I need to scan for.
My assumption with "what shall the output" is what should your print out be of.
Basically i want the print out to be of the initial display of the grid.
Hopefully this has made it easier to understand.
-
James, if the files just need to be displayed on the screen, then all you need to do is open the file with fopen, read in lines with fgets, until the end of the file, and print each line out after reading it with printf or fputs.
The fgets will return NULL when you've hit the end of the file. You need a char array to hold the line.
Do you need to draw the actual grid? Something like this:
Code:
+-+-+
|A|B|C
+-+-+
|E|F|G