Hi!
I want to create a program "file splitter". The whole file size is 5 MB. My problem is that I do not know how to create files .001, .002, and so on, and every file has maximum size 1.4 MB.
Any ideas?
Hi!
I want to create a program "file splitter". The whole file size is 5 MB. My problem is that I do not know how to create files .001, .002, and so on, and every file has maximum size 1.4 MB.
Any ideas?
Current projects:
1) User Interface Development Kit (C++)
2) HTML SDK (C++)
3) Classes (C++)
4) INI Editor (Delphi)
The filename is known, so you only need to adapt the extension.
Open the inputfile as binary and create the new file, also binary and copy the bytes to the new file until 1.4 MB is reached. Then you close the new file and open a new file. This new file will also be filled with bytes. Do this until the end of the inputfile is reached.
You can use the function feof to check if the end of the input file is reached:
while (!feof (inputfile))
{
..
}
The bytes can be read using the function fgetc:
inputbyte = (unsigned char) fgetc (inputfile);
And bytes can be written using fputc:
fputc ((int) outputbyte, outputfile);
Hope these hints will help. Note that there are other ways to implement the algorithm, this is just one of them.
How do I adapt the extension? This part of the program is bugging me. Is there any command to do that?
Current projects:
1) User Interface Development Kit (C++)
2) HTML SDK (C++)
3) Classes (C++)
4) INI Editor (Delphi)
The following code will format a file name with an extension you can control.
Output:Code:int main(void) { char FileName[31]; int i; for (i = 0; i < 5 ; i++) { sprintf(FileName, "filename.%03d", i); printf("%s\n", FileName); } return 0; }
filename.000
filename.001
filename.002
filename.003
filename.004
Thanks.
Current projects:
1) User Interface Development Kit (C++)
2) HTML SDK (C++)
3) Classes (C++)
4) INI Editor (Delphi)