Q2 A binary file question
ASCII files on dos/windows store both CR (ascii 13) and LF(ascii 10) to indicate the end of a line of text. On unix only LF is used. As a result, when you transfer text files from unix to dos machines (or vice versa) you need to set the mode to ascii or the resulting platform would not be able to process the data correctly.
Write the following function:
void Process(fstream& fs, int recsize);
This function is passed an instance of fstream fs. fs is associated with a file that is open in binary mode for both reading and writing (so don't try to open the file because it is already open). The second parameter recsize is the size (number of bytes) of one record in the file associated with fs. The last two bytes of each record is always CR and LF respectively. Your function needs to read out each record then write it back into the file such that the CR at the end of each record is removed.</br>
NOTE: it is important that you only remove the CR from the end of the records. If they occur elsewhere within the record you should ignore it.