Skip to content

Corg-Labs/file-splitter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 

File Splitter in C

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)


Features

  • 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()

How It Works

  • Reads command-line arguments for filename and number of splits
  • Opens the input file using fopen()
  • Determines file size using fseek() and ftell()
  • 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-part0
    • filename-part1
    • etc.

Build

Compile using:

gcc -Wall -Wextra -g -o filesplitter filesplitter.c

Usage

Run:

./filesplitter <filename> <num_splits>

Example:

./filesplitter movie.mp4 4

This creates:

movie.mp4-part0
movie.mp4-part1
movie.mp4-part2
movie.mp4-part3

Example

Input:

movie.mp4 (1 GB)

Command:

./splitter movie.mp4 5

Output:

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.


Notes

  • 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

Concepts Practiced

  • File handling in C
  • fopen()
  • fseek()
  • ftell()
  • fread()
  • fwrite()
  • Dynamic memory allocation
  • Pointers
  • Buffers
  • Command-line arguments
  • Binary file processing

Future Improvements

  • Merge split files back together
  • Progress bar support
  • Configurable buffer size
  • Better error handling
  • Support for extremely large files
  • Multi-threaded splitting

About

► A minimal command-line file splitter written in C.

Topics

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages