Problem with the fopen(); function.

The simple glitches like this one are always problematic. I wrote a program that generates a file. I wrote another program that calls this program and opens the generated file afterwards.

Here is an example of what the code looks like:
1
2
system("new_file.exe file.txt");
FILE *txt=fopen("file.txt","rb+");

It seems that edits made to file.txt are not saved, however. This is a simple example. In my actual code, one program calls a converter that I wrote and it would be sloppy to port the code for the converter over to the main program, so it must remain as a simple executable. Therefore, solutions such as "remove the call to new_file.exe and use wb+ instead" will not suffice. It is as if the file is still locked by the other program or something.
system() will not wait until the command execute ends.
Besides, you should not use system().
Use ShellExecute instead, or CreateProcess (who also allows you to wait until process termination I believe).
You're right. That completely slipped my mind. With Windows, it actually does wait, but I have been emulating the EXE files via Wine from Linux, where it does not wait. Adding in a delay after the system(); command solves the problem. Thanks!
Topic archived. No new replies allowed.