It probably is working but the working directory of the program when windows boots may not be where your program is. You can either search your HD for myfile.txt or specify the path in your cpp file with something like: file=fopen("c:\\myfile.txt","a+");
so that where ever it is executed from it will output the file to the same place.
I searched in my c: drive. found the file on system32 folder.
But how the working directory can change. my application placed in "c:\myapplication\HelloWorld.exe". how it can write it in system32 folder.
Just to get the current directory from the application i add some code.
I don't know for sure why the working directory is set to system32, but as most of the files Windows loads at boot time will be in that directory, is makes sence to set it there.
Whatever Windows uses to invoke your program either sets the working dir to system32, or at least dosn't change it from system32 to the path of your program. (you can see how working directorys are used by looking at the properties of a shortcut icon)
You can force your program to store it's files in a place you specify by including the path in your code as I showed above, you could also use the argc and argv perameters passed to main() as a method to alter where you want the output files to go, and then change your registry key to pass in a directory.