When you call fopen("compfile.txt", "wb");
the existing file (if any) gets truncated to zero length. To make this work, you need to open the file once at the beginning of the program, and then fclose
the file at the end of the program.
Also, to view the file, you need to use a hex editor.