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 18.104.22.168 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.