the parameter w+ dosn't help, it only place the file pointer at the beginning of the file.
April fools?
fopen()
w+
Open for reading and writing; place the file pointer at the beginning of the file and truncate the file to zero length. If the file does not exist, attempt to create it.
w+ does exactly what you want - i cannot reproduce your problem.