Don't forget to check fwrite returns for errors! Just because you successfully opened a file for write, doesn't always mean you can write to it.
On some systems this can occur if the filesystem is full, you can still open the file and create the filesystem inode, but the fwrite will fail, resulting in a zero byte file.