Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

C++ reading textfile into 2d array

Name: Anonymous 2009-12-01 14:20

Ok, anon. I am trying to teach myself C++ and one thing I would like to be able to do is read a text file that is 4 x 4 characters
xxxx
xoxx
xxox
xxxx

into a 2d char array of [4][4]

but I'm pretty confused and google seems pretty shit searching for more specific stuff like this

I can open/close files and print arrays to the screen and shit I just don't know how to assign the characters in the text file to the array.

thanks ;]

Name: Anonymous 2009-12-01 15:44

>>1
You don't know how to do WHAT?

Use two loop indices to indicate array indices - array[j][i], where 0 <= i,j < 4.  Read the file one character at a time and put that character into the array at the given column position; then, increment the row index, set the array column index back to 0, and start reading the next line; keep going until eof or array full.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List