I have some code to save a map:
And some code to load it:Code:void Save() { COORD Pos; HANDLE hOt = GetStdHandle(STD_OUTPUT_HANDLE); DWORD reader; char buffer[2028]; char DELO[1]; int x_pos, y_pos; SHORT bc; for(bc=0; bc < 2028; bc++) DELO[0] = ' '; bc=0; ofstream file_out(MAINPATHNAME); file_out << ""; if(!file_out) { clrscr(); cout << "Unable to open file!"; } for(y_pos=0; y_pos <= 24; y_pos++) for(x_pos=0; x_pos <= 80; x_pos++){ bc++; Pos.X = x_pos; Pos.Y = y_pos; ReadConsoleOutputCharacter(hOt, &DELO[0], 1, Pos, &reader); if(x_pos == 80) { buffer[bc] = 'W'; } else buffer[bc] = DELO[0]; } for(bc=0; bc < 2028; bc++) { if(buffer[bc] == 'W') file_out << endl; else file_out << buffer[bc]; } file_out.close(); clrscr(); exit(0); }
Now, when I save the map, it saves, but it saves some weird characters that shouldent be there also...Code:void load() { char DELO[1]; SHORT x; ifstream file_in(MAINPATHNAME); if(!file_in) cout << "cannot open file."; for(x=0; x < 2050; x++) { if(!file_in.eof()) break; file_in.getline(map, 1); } cout << map; }
And when I try to load, it doesnt work at all? I'm a noob with files :/. I'm sure I messed something simple up, but I cant find any help on the matter. :/.



LinkBack URL
About LinkBacks




.