Click here to Skip to main content
15,867,453 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
So far, whenever I compile a program in C that creates a file, the previous data written on it is erased in order to write the new data. As a result, I was wondering if there was a way to save the information that had already been written in the previous compilation and then add and store new data in such a file.

As a result, I was wondering if there was a way to save the information that had already been written in the previous compilation and then add and store new data in such a file.


What I have tried:

If it's possible, could you give me a simple example, please?
Posted
Updated 23-Feb-23 23:34pm

1 solution

If you mean the file your C program creates, then you might open it in append mode, see fopen, fopen_s - cppreference.com[^].
On the other hand, if you mean the product(s) of the compilation process, then you should save such file(s) before compiling again (note you could automate such a task, as post-buil step).
 
Share this answer
 
Comments
Auyik 24-Feb-23 12:28pm    
Interesting. Could clarify a bit more what you mean by "the product of the compilation process", please?
CPallini 24-Feb-23 13:24pm    
The major product of the compilation process is the executable file. However there are also object files and possibly assembly listing files, and linker map ones.
Auyik 24-Feb-23 15:32pm    
Thanks. I have another question, what are the methods to automate the task of save the file before compiling again?
CPallini 24-Feb-23 16:54pm    
Usually you write a batch file for that. Such a file is then executed by your favourite IDE as post-build action (or invoked, after the build, in your makefile).
Auyik 24-Feb-23 16:57pm    
Thank you!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900