- This topic has 4 replies, 2 voices, and was last updated 10 years, 5 months ago by Anonymous.
September 4, 2009 at 4:31 pm #7408AnonymousInactive
I currently have a map file in a txt format. such as the below code
[code:1:1cc512fea1]1:0 0:0 0:0 1:0[/code:1:1cc512fea1]
I need a way to separate them out without using fscanf().
For example the way my map format works is the space is the delimiting character and then the first number on the left hand side of the colon is the TileID and then the number the other side is TileType.
I have tried to use getline() but it doesn’t allow the same functionalty as fscanf(); Such as the code below
[code:1:1cc512fea1]fscanf(FileHandle, "%d:%d ", &tempTile.TileID, &tempTile.TypeID);[/code:1:1cc512fea1]
September 5, 2009 at 5:53 am #44550AnonymousInactive
I’d be inclined to store this map data in XML or INI file and use (or write) a respective parser.
I guess it depends on the scope of the project. Are you familiar with the concept "Data Driven Design?"
Also found this, which seems closer to the solution that your looking for:
while ( getline(f, str) )
sscanf(str.c_str(), "%f, %f, %f\n", &p.x, &p.y, &p.z);
September 5, 2009 at 9:47 am #44553AnonymousInactive
Thanks very much for your reply
I have read some of that book before alright. I do take that approach as much as I can. Like for example in this project to load images into memory and onto a surface (using SDL by the way) I use a class method that reads the names of the images from a text file thus adding new titlesets without having to recompile etc.
Also that code solved my problem, its always something so simple.
I was using the below function
And it was throwing an error that I needed a FILE* and I was using ifstream.
Its so obvious that the f stands for file and in sscanf() s for string or maybe I am wrong but I think I understand it all now.
while ( getline(myfile, TempContainer, ‘ ‘ ) )
sscanf_s(TempContainer.c_str(), "%d:%d ", &tempTile.TileID, &tempTile.TypeID);
Above is the code I used in the end, the compiler told me to use sscanf_s() instead of sscanf() due to a security hole in the function or something to that effect.
September 6, 2009 at 10:18 pm #44557AnonymousInactive
Glad to be of help.
As for the "_s", that tends to stand for "secure", its the same function, but usually takes an additional size parameter to avoid buffer overflows.
So when do we get to play this game of yours???
September 7, 2009 at 9:55 am #44559AnonymousInactive
I see, thanks for the info.
Oh well now that might be a long time, I am just developing the engine atm, well if you could call it that. So far I have the map loading and titling systems done. Moving onto event management and animation next, then collisions.
Fairly new to SDL so trying to learn by doing. Probably doing it all wrong, and probably have loads of loss pionters ha but it works.
I posted a video on youtube of what I got to so far.
- The forum ‘Programming’ is closed to new topics and replies.