Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please answer the queston (in terms of C programming) and explain answer Semeste

ID: 3905565 • Letter: P

Question

Please answer the queston (in terms of C programming) and explain answer

Semester 2 &Trimester; 3B, 2015 COMP1004 Engineering Programming Q5(b) Implement a complete C program that will read a data fle, cale contains one integer value per line. An example of this fle format witt ollows rel 98 rt 65 e total number of items in this file is not fixed so you must use an appropriate should print these items in a reverse order into a new file, caled "data reverse.dat". The ote that th in your program. After reading the items on this file, the program content of this new file for this particular example is therefore: 65 98 [11 marks)

Explanation / Answer

#include void write_in_reverse(FILE *fr, FILE *fw) { int num; if(fscanf(fr, "%d", &num) > 0) { write_in_reverse(fr, fw); fprintf(fw, "%d ", num); } } int main() { FILE *fr = fopen("data.dat", "r"); FILE *fw = fopen("data_reverse.dat", "w"); if(fr) { write_in_reverse(fr, fw); } fclose(fr); fclose(fw); return 0; }