advice for dealing with files

Hi everyone, so I'm making a program that lets the user make a crossword puzzle. I have some pseudo code for the input/output. But I don't know how to handle file for this. The puzzle itself will be stored as a 2d array of strings/chars in a separate file.

My question is, what file type should I use? How can I manipulate the array in the file? Is that even possible? I've only seen strings be stored/manipulated in files, but no more than that.
Manipulating the array in the file is not easy. I'm not quite sure I understand your statement about "The puzzle itself will be stored as a 2d array of strings/chars in a separate file." Are you trying to figure out how to write the puzzle to the file?
I mistyped, it lets the user solve a crossword puzzle I've made.

The empty puzzle is already in the file, stored as a 2d array. What I was planning to do is to open the puzzle file, and then the user will fill in the puzzle. The program will then receive a cstring, and then fill in each array element with a character from that cstring.

What I'd like to know is if I can manipulate the array like I normally would-as if it wasn't in a separate file. By manipulate, I just mean can I open the file containing the array, and go

characterarray[i][j]=charfromuserinput;

....if that makes sense.
OK, that is much clearer. I think it's going to depend on how you have the empty puzzle stored.

One way you could do it is to store the completed puzzle in the file, sort of like this:


___Foobar__Duck__
A__o__a____i_____
p__r__l____l_____
p__d__l____l_____
l____D___________
ear__o___________
_____o___________
_____r___________


where the underscores indicate a solid box.

So the algorithm for reading in the puzzle is:

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

Open the file

while( ! eof )
    {
    Read a line

    if eof
        {
       break;
        } // if( eof )
    else
        {
        //    Start a for-loop for all characters in this line:

        for( int i = 0; i < the length of the line; i++ )
            {
            if( the current character is an underscore )
                {
                output a solid box
                }
           else
               {
               output a space

               }

             }    // for-loop

        }  // if( ! eof )

    }  // while ! eof


In this input loop I would also store the entire puzzle in another array so you can compare the user's input to the actual puzzle solution.

Got it, that makes sense and I could just use a similar loop when the user writes into the crossword.

Thank you!
Yep! That's what I was thinking!
Topic archived. No new replies allowed.