The "mode" flag in the fopen() call defines what happens to the file at the path you specify.
r and r+ :: Read the file only, no writing.
w and w+ :: Write to a file, if it doesn't exist, create it. If it has data, remove all of it.
a and a+ :: Write to a file, if it doesn't exist, create it. If it has data, go to the very end of the file and start writing.
x and x+ :: Create and open the file for writing only. If it already exists, the fopen call will fail.
All of this can be found on the [man]fopen/man manual page.