What you need is a debugger, not fwrite or printf.
Visual Studio has a nice debugger, and within its sortiment, it allows you to put breakpoints when a certain position in memory changes (in other words, you can have it break when your buffer is changed, or corrupted), to see what caused the change.
It makes debugging so much easier.