A minimal command-line file splitter written in C.
The program reads a file in fixed-size memory blocks, splits the file into multiple smaller parts, and writes each part into separate output files.
This project focuses on learning low-level file I/O, memory management, buffers, and command-line argument handling in C.
Tutorial: Video Tutorial Available (by Daniel Hirsch)
- Split files into multiple parts
- Works with large files
- Uses buffered file reading/writing
- Simple CLI interface
- Uses low-level C file operations
- Dynamically allocates memory using
malloc()
- Reads command-line arguments for filename and number of splits
- Opens the input file using
fopen() - Determines file size using
fseek()andftell() - Calculates:
- part size
- remaining bytes
- Allocates a temporary memory buffer using
malloc() - Reads chunks from the source file using
fread() - Writes chunks into split files using
fwrite() - Generates output files using:
filename-part0filename-part1- etc.
Compile using:
gcc -Wall -Wextra -g -o filesplitter filesplitter.cRun:
./filesplitter <filename> <num_splits>Example:
./filesplitter movie.mp4 4This creates:
movie.mp4-part0
movie.mp4-part1
movie.mp4-part2
movie.mp4-part3
Input:
movie.mp4 (1 GB)
Command:
./splitter movie.mp4 5Output:
movie.mp4-part0
movie.mp4-part1
movie.mp4-part2
movie.mp4-part3
movie.mp4-part4
Each part contains approximately equal portions of the original file.
- The program processes files using a fixed buffer size (
BLOCK_SIZE) - Remaining bytes are added to the final split file
- Output files are generated by appending:
-part<number>
to the original filename
- Large files may take time depending on disk speed
- File handling in C
fopen()fseek()ftell()fread()fwrite()- Dynamic memory allocation
- Pointers
- Buffers
- Command-line arguments
- Binary file processing
- Merge split files back together
- Progress bar support
- Configurable buffer size
- Better error handling
- Support for extremely large files
- Multi-threaded splitting