First off, to open a text file, you have to use a FILE*, and the function fopen.
- Code: Select all
FILE* file = fopen("fileName", "r");
The "r" means you will just read the file, but in your case it sounds like you might want to completely overwrite it. To do that use "w" instead. But, if you want to update a file, you can use "r+". There are several more options, but those should cover most of the things you would do.
Next you have to write the actual text into the file, so you can use this.
- Code: Select all
FILE* file = fopen("fileName", "w");
fprintf(file, "Level1\nLevel2\n");
fclose(file);
That will print what you want into the text file, but of course it isn't dynamic. If you want to write more than that, I'd have to know how you are creating the information that you want to write into the file. But, when you are done editing the file, you need to close it, like in the above code. The format for fprintf is the same as for sprintf if you know how to use that.