Reputation: 125
If the file doesn't exist I want to create it. But the next time that the program runs I want to open the file without losing its previous contents. Can anyone help? I have one function that loads the file and another that saves the file. I just don't know what mode I should use
Upvotes: 0
Views: 1049
Reputation: 11
You can update the already existing text with a call to fopen
using append mode, so to update this previously created file without erasing the data you can use the mode "a"
like this:
ptr = fopen("file_name.txt","a") //(a=append)
This will add your fprintf
ed strings or other inputted data at the end of the .txt
file, instead of overwriting from the beginning
Upvotes: 1