I am sure this is a very simple question, but it has been quite some time since I had to open a file and read it.
Anyway, I have a file called levels.ini and it looks like this
I want to be able to pass "Level1" to a function that reads the file until it finds "Level1" and then reads the numbers and game grid into variables. Can anyone point me to any reference regarding this.
The format specifier in this case will change depending on what part of the file you want to read. To handle the first portion of the file you will probably want to have a character, lets say char sInput, that takes character data. for int''s, let say iInput.
The above poster is on the right track. However, the "Level" name poses a minor problem. First off there is no way to determine when you''ll see "Level" unless your specificaly looking for the whole word. I highly suggest using a special character like ! before you define the word "Level" so it would look like this.. "!Level 1" Then you can search through the file for the specific special character that your using rather than searching for a whole word. This also allows you to determine how many levels you have just by counting the number of special characters in the file...
There''s actually a bunch of Windows functions for dealing with .ini files. You''d simply need to rename each of your sections (from "Level1" to "[Level1]", etc) and place an identifier before each of your values. Then you''d use Get/WritePrivateProfileString(). Look it up in MSDN.