Hey there!
I've encountered some issue with a file loading system I've been working on for an infinite randomly generated RPG game.
For now, I'm using a char array as a display/world map and need to be able to read and write said array to and from files (at the moment, I'm using simple text files because this is my first week of programming in C++).
Here's what the text file looks like:
##############O##############
#,__________#____"__________#
###___,___,_____"______,_#_##
#_____,________E____________#
#______,__#__E_____##_______#
##____#,_______________,#___#
#_,_______#___#______",___#_#
O##__________#__#_,#,_______O
##_,_E_____<_____#___#______#
#_______#______",_______#_#_#
#_#__"_______________#___"__#
#________,__________#_______#
#"_________#____"___""_",_,_#
#___________________________#
##############O##############
(It's uniform in the actual file, don't worry...)
Here's my code for reading from the file above:
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
|
void load()
{
string a;
cout << "Please input a file name." << endl;
cin >> a;
ifstream myfile;
myfile.open (a);
char loadarray[16][30];
for(int e=0;e<16;e++){
for(int q=0; q<30; q++){
myfile.get(loadarray[e][q]);
}
int q=0;
}
map [7][14] = '>';
x=14;
y=7;
myfile.close();
memcpy(map, loadarray, sizeof(map));
}
|
It works....almost. It loads the map successfully...and then some.
http://imgur.com/Hq3IUuk
I feel like I'm missing the obvious here, but if not, is there any way to modify memcpy to fix this?
Thanks,
-ConfigMC
EDIT: After fooling around with it for a long time I found it was actually the display that was causing the odd behavior.