Change code to use open/read/write/close instead of fopen/fread/fwrite/fclose.