Original Post
So, how would I fix the following code to work? I _can_ get it to work if I change the definition:
char* city[2][11];
to:
char city[2][11][21];
and some other minor changes in code. The thing is I don''t want to do this. Please help!
/john
*Save GameDev - donate*
// testly.cpp
//
#include "stdafx.h"
#include <iostream>
#include <fstream>
using namespace std;
void SaveMap (char *filnamn);
void LoadMap (char *filnamn);
char* city[2][11] =
{
{ // //
"LAYER1LAYER1LAYER1LA",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
"LAYER1LAYER1LAYER1LA",
// //
},
{ // //
"LAYER2LAYER2LAYER2LA",
" ",
" ",
" korv ",
" ",
" ",
" ",
" ",
" ",
" ",
"LAYER2LAYER2LAYER2LA",
//12345678901234567890//
}
};
int main(int argc, char* argv[])
{
//Display map
for(int Layer=0;Layer<2;Layer++)
for(int y=0;y<11;y++)
cout << city[Layer][y] << "\n";
SaveMap("korvboll.txt");
cout << "\n" << "::loading saved file::" << "\n\n";
LoadMap("korvboll.txt");
//Display loaded map
for(Layer=0;Layer<2;Layer++)
for(int y=0;y<11;y++)
cout << city[Layer][y] << "\n";
return(1);
};
void SaveMap (char *filename)
{
ofstream fout(filename);
for(int Layer=0;Layer<2;Layer++)
for(int y=0;y<11;y++)
fout << city[Layer][y] << "\n";
fout.close();
}
void LoadMap (char *filename)
{
char name[21];
ifstream fin(filename);
for(int Layer=0;Layer<2;Layer++)
for(int y=0;y<11;y++)
fin.getline(city[Layer][y],21);
fin.close();
}
|