Welcome to Software Development on Codidact!
Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.
1 answer
+5
−0
Simply opening a file for writing (using fopen
) will clear it (‘truncate to zero length’, per the standard). Only opening a file in read or append mode will preserve its contents.
See section 7.21.5.3 of a recent C standard (like this draft) to get it straight from the horse's mouth, or any of the various man pages or C tutorial sites you can find by searching for ‘fopen
’ on the web.
0 comment threads