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; }Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.