cxzuk wrote:
Code:
sscanf(s_TileMapVALUE, "%d", &TileMap_base[y][x]);
Your input is not being consumed with a char *, while your file is. The line above says find the first int in s_TileMapVALUE and place it at TileMap_base[y][x]. The first value in s_TileMapVALUE is the same value through out the loop.
You can see this if you change the first "0" in the char to a "1", which will turn all entries into your TileMap_base into "1"s
The solution is most likely a little more complex, Why can you not pass the int data structure to start with?
Mikey
Thanx Mikey,
that helped me a lot, as now I realized that yeah... this will probably be the part of C++ travails that are inevitable to walk the road further.
char * points to 1st entry, as I've heard before... pointer initially points at 1st entry in array..
To start with int data structure? What do you mean exactly? To use rather class or struct for 2D Tile map storing of X, Y coordinates etc.?
I've already thought about the possibility I guess, BUT I must keep in mind that I need to have it available to just load string from external file - text file that carries more than just tile values of the map, one file for all map specs, including name of the map, its size, objects on it, and of course tiles.
That's why I have my own parsing function for it... map "tile values string" would be one field to extract from the file into string - and THAT would be later
sscanf-ed.
Therefore, fscanf is not the exact thing that would be useful.
I already have had this before - in the init of my .cpp file
Code:
TileMap_base = {{1,1,1,1,1,1,1,1,1,1},
{1,1,1,1,1,1,1,1,1,1},
{1,1,1,1,1,1,1,1,1,1},
{1,1,1,0,0,1,1,0,1,1},
{1,1,1,1,0,1,0,1,0,1},
{1,1,1,1,0,1,0,1,0,1},
{1,1,1,1,0,1,0,1,0,1},
{1,1,1,0,1,1,1,0,1,1},
{1,1,1,1,1,1,1,1,1,1},
{1,1,1,1,1,1,1,1,1,1},};
That means if I don't call a function to load map after this, this will be as a default just for now.
Of course, for every map editor it is intended to load & save maps into some external file (and I guess everyone will manage the specs and order or parsing and storing the data inside the file on his own for some reason). One of the data fields should be that 2-Dim array as a value, but since C++ is compiled, I can't have it as an expression and just tell the .cpp file "treat this expression in txt file as a code" :/.. I guess what you can do with fscanf, can be done with sscanf as well, but maybe with some modifications.
If I look into function specs of fscanf
http://www.cplusplus.com/reference/clib ... io/fscanf/it looks like it takes
FILE * stream as first argument - as a file you mentioned is being consumed whole... but HOW? and why?
I can hardly believe such a thing would be a great problem... cannot C++ take somehow whole string as if it was a
FILE * stream passed to fscanf? The content of a .txt file is pretty much the same as any string, consisting of either numbers or chars or words.. of chars in general (numbers, letters and punctuation are all chars) But in terms of C++ it seems to have differences? What are they?