Computer Science, asked by MounikaMuddada0211, 2 months ago

Write a C program to Copy last n characters from one File to another File​

Answers

Answered by shahmirahmed7777
0

Answer:

This is the program I have written which copies all the lines from diskData.dat file to 24HrDiskData.dat file. As of now I am copying all the lines from one file to another I wish to copy last n lines from diskData.dat to 24HrDiskData.dat

#include <iostream> #include <stdio.h> #include <fstream> #include <stdlib.h> using namespace std; int main(int argc, char *argv[]) { FILE *HrData; char tempData[1024]; int flag = 0; ofstream fout; fout.open("24HrDiskData.dat", ios::app); // open file for appending assert (!fout.fail()); if ((HrData = fopen("/home/xvishuk/diskData.dat", "r")) == NULL) { printf("\nFile cannot be opened"); } while (fgets(tempData, 1024, HrData) != NULL) { fout << tempData; // write the data to the file } return 0; }

Similar questions