-
spliting large files
hi
i am writing a programm that splits large text files (2gb+). what i am doing for now is that i reads and copy the file to a new one till i found a special marker in the text and then close the outputfile and open a new one and so on. something like:
[CODE]
while(~EOF) {
fopen(myfile.....);
while(marker not found) {
fputc(fgetc(source),newfile);
}
}
Problem, while performing on the file, i need twice the size of the file. isn't there a way to get the position where to split and the simply dividing a large file in two without copying?
thanks
-
Only if you read the whole file into memory, then remove the file, then save it in parts. This is kinda risky though. Your program could crash in the middle of the process, completely removing the file. Plus, having several gigs of RAM is pretty rare.