Stuck on something new how to copy a very large file in C

Onceler

Golden Member
Feb 28, 2008
1,262
0
71
Code:
#include <stdio.h>


int main()
{
    FILE *to,*from;

    from=("g:\\Mess.m2ts","rb");
    to=("g:\\Mess2.m2ts","wb");
    fopen64 from,to;

    fread from;
    fwrite to;


   return 0;
}
I have no idea what I am doing, I have been awake for three days, yesturday this made sense now I don't know what I am doing.
I am attempting to test wether fread and fwrite work as is on a very large file, my google searches have led me to believe that they get messed up with files that are >than 2 GBs.
I wanted to test if this was true and if so get some help for it.
I am attempting to manipulate a very large file in excess of 30GBs and test it under all conditions to make sure that LFS works with my compiler(GCC) or if something else is needed.
Code::Blocks tells me that it is expecting a ';' before fopen64 from,to;
here is the error message C:\Users\Benjamin\Documents\copy.c||In function 'main':|
C:\Users\Benjamin\Documents\copy.c|10|warning: assignment from incompatible pointer type [enabled by default]|
C:\Users\Benjamin\Documents\copy.c|11|warning: assignment from incompatible pointer type [enabled by default]|
C:\Users\Benjamin\Documents\copy.c|12|error: expected ';' before 'from'|
C:\Users\Benjamin\Documents\copy.c|14|error: expected ';' before 'from'|
C:\Users\Benjamin\Documents\copy.c|15|error: expected ';' before 'to'|
||=== Build finished: 3 errors, 2 warnings (0 minutes, 0 seconds) ===|
should I be doing fgets and fputs instead and how do I define and manage a buffer?
 

lambchops511

Senior member
Apr 12, 2005
659
0
0
Code:
#include <stdio.h>


int main()
{
    FILE *to,*from;

    from=("g:\\Mess.m2ts","rb");
    to=("g:\\Mess2.m2ts","wb");
    fopen64 from,to;

    fread from;
    fwrite to;


   return 0;
}
I have no idea what I am doing, I have been awake for three days, yesturday this made sense now I don't know what I am doing.
I am attempting to test wether fread and fwrite work as is on a very large file, my google searches have led me to believe that they get messed up with files that are >than 2 GBs.
I wanted to test if this was true and if so get some help for it.
I am attempting to manipulate a very large file in excess of 30GBs and test it under all conditions to make sure that LFS works with my compiler(GCC) or if something else is needed.
Code::Blocks tells me that it is expecting a ';' before fopen64 from,to;
here is the error message C:\Users\Benjamin\Documents\copy.c||In function 'main':|
C:\Users\Benjamin\Documents\copy.c|10|warning: assignment from incompatible pointer type [enabled by default]|
C:\Users\Benjamin\Documents\copy.c|11|warning: assignment from incompatible pointer type [enabled by default]|
C:\Users\Benjamin\Documents\copy.c|12|error: expected ';' before 'from'|
C:\Users\Benjamin\Documents\copy.c|14|error: expected ';' before 'from'|
C:\Users\Benjamin\Documents\copy.c|15|error: expected ';' before 'to'|
||=== Build finished: 3 errors, 2 warnings (0 minutes, 0 seconds) ===|
should I be doing fgets and fputs instead and how do I define and manage a buffer?

first link on google search...
http://stackoverflow.com/questions/10195343/copy-a-file-in-an-sane-safe-and-efficient-way
 

lambchops511

Senior member
Apr 12, 2005
659
0
0
I personally like this the best

#include <iostream>
#include <fstream>
#include <ctime>
using namespace std;

int main() {
clock_t start, end;
start = clock();

ifstream source("from.ogv", ios::binary);
ofstream dest("to.ogv", ios::binary);

dest << source.rdbuf();

source.close();
dest.close();

end = clock();

cout << "CLOCKS_PER_SEC " << CLOCKS_PER_SEC << "\n";
cout << "CPU-TIME START " << start << "\n";
cout << "CPU-TIME END " << end << "\n";
cout << "CPU-TIME END - START " << end - start << "\n";
cout << "TIME(SEC) " << static_cast<double>(end - start) / CLOCKS_PER_SEC << "\n";

return 0;
}
 

Onceler

Golden Member
Feb 28, 2008
1,262
0
71
Thank you. I think that I need to sleep in a few hours maybe it will come to me after I have rested.
That code is C++ not C.
 
Last edited:

Ken g6

Programming Moderator, Elite Member
Moderator
Dec 11, 1999
16,511
4,360
75
I don't know about you, but the answer just came to me:
Code:
#include <stdlib.h>
...
system("xcopy \"g:\\Mess.m2ts\" \"g:\\Mess2.m2ts\"");
 

Onceler

Golden Member
Feb 28, 2008
1,262
0
71
I don't know about you, but the answer just came to me:
Code:
#include <stdlib.h>
...
system("xcopy \"g:\\Mess.m2ts\" \"g:\\Mess2.m2ts\"");

Thank you. Yes that does work. But it does not leave any room for tampering with the stream. Like writing different values to the output stream then they were in the input stream.
I had this working like I wanted it but have lost the source code(not the hard drive crash excuse) but I cannot find it. If I could find the original source code that someone either on this or another forum posted I could modify it again. I think that it was with fread64.
 
Last edited:

EagleKeeper

Discussion Club Moderator<br>Elite Member
Staff member
Oct 30, 2000
42,589
5
0
You asked about copy. Those were the answers to your question.

That is different that reading a large file and writing a large amount of data to a file.

Read up on file I/O