I have an array of strings and I would like to modify its elements at will. This is the code:
char pieces[9][4] = { " ", " o ", " a ", " ", " ", " ", " b ", " ", " " };
pieces[2] = { " x " };
As I know, the elements in pieces[] are string literal, so they can't be changed (I'm not sure why this is like this). Maybe it could be solved using std::string or vectors. However, I would like to know if this kind of operation, or very similar operations, can be done using an array of strings. Can be done something like this using just an array of strings?
char[]initialized from a string literal certainly can be changed.char *pieces[9] = { ... };. But since you declared itchar pieces[9][4], the elements ofpiecesare arrays, not pointers to literals.