Check the modes you're using to open your input files. All three files are being opened O_RDWR (which means you can both read and write them). O_APPEND (which you're using for the first input...