Now heres the problem. I want to replace the "f" with another "." so i have this code at the moment:
maze[y] = "l......l> ";
which works in replacing the "f" with an "." but this isnt practical, cause if the "f" was in another place, the code would need to change. So i tried
maze[y][x] = '.';
but i get some weird error: Unhandled exception at 0x012f5aee in Text Game.exe: 0xC0000005: Access violation writing location 0x012f8920.
My question is how can i replace the "f" with a "." without having to replace the whole line?
Sorry if this is a bit vague, but can ANYONE help?
Thanks in advance,
Sysem
You could do that by casting your "..." to std::string (otherwise, const char* is assumed). That would be for lines 1-11:
maze[x] = std::string("...");
if your maze array is an array of string then you don't need maze[y][x] = string(".");
This will try to replace the 'f' with a string. You need to replace 'f' with a '.' maze[y][x] = '.';
Of course, whenever you expected your old array, you now have to use the vector. It might seem a bit complicated at first, but nevertheless you should use it. The type of array you were using is called "C-style array". It is in C++ merely for compatibility with C. You sholudn't use it in most cases. The C++ substitute for C-style arrays are vectors, used as in the example:
vector<T> my_vector(size);
where T is any typename (like int, char*, std::string, ...) and size is the initial size. It can be ommited for a size of 0 (vectors can be resized using either resize() or push_back()). One advantage over a C-style array is, among many others, that vectors know their size. So if you want a larger maze, you can simply "push_back" one more line, and if your other code is dependent on maze.size() rather than a fixed number, everything works fine with the new size.
Just rewrite your functions from
void f(char* maze[10])
to
void f(const std::vector<std::string> >& maze)
and most of the errors should vanish. For the rest, just ask ;-)