Hello, I did this programu to read and write the close a program when you have 2 files the problem is how can I edit this program first to copy the whole file and on the same time copy the part of it ..any boday have this code.. Code: #include <iostream> #include <fstream> #include <conio.h> using namespace std; #define NAMELEN 20 int main (int argc, char *argv[]) { char *source, *target; void sequence(char*,int,char*); int i; int numBytes; int seq; if (argc != 4) { cout << "Wrong format\nThe command:\n" << argv[0] << " source target bytes\n"; exit(1); } if (strlen(argv[1]) >=NAMELEN-1) { cout << "Please check file name, it is too long\n"; exit(0); } if (strlen(argv[2]) >=NAMELEN-1) { cout << "Please check file name, it is too long\n"; exit(0); } source=argv[1]; target=argv[3]; numBytes=atoi(argv[2]); sequence(source,numBytes,target); getch(); } void sequence(char* src,int nbytes,char* tgt) { ifstream inFile ; ofstream outFile(tgt, ios::out | ios::binary); char *msg; msg=new char[nbytes]; inFile.open(src, ios::in | ios::out | ios::binary); inFile.seekg (0, ios::end); int fileSize=inFile.tellg(); inFile.seekg (0, ios::beg); if(nbytes<=fileSize) { inFile.read(msg,nbytes-1); cout<<msg<<endl; outFile << msg<<endl; } else cout<<"Required size is greater than filesize"<<endl; inFile.close(); outFile.close(); }
I was traying to edit my thread but it seems iam not be abel to edit it .any way my question is fisrt when I copy the file myprogram test1.txt test2.txt. in the second case myprogram test1.txt the offset the length test2.txt. I hope this is clear now.