Skip to content
Fai707Public

About

A collection of string manipulation tools in C

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Latest commit

 

History

15 Commits

Folders and files

Repository files navigation

C-TextKit

A collection of lightweight command-line utilities written in C, focused on string manipulation, pointers, buffers, and fundamental systems programming concepts.

Overview

C-TextKit is a personal learning project built to strengthen my understanding of the C programming language through practical command-line tools.

Rather than relying entirely on high-level string manipulation functions, these programs explore how strings and memory are handled at a lower level.

Tools

Tool Description
trimcli Removes leading, trailing, or surrounding whitespace
bufcopy Copies text into a fixed-size buffer with capacity limits
argsplit Splits a string into individual arguments
replacecli Performs text replacement
heapstats Calculates the sum, minimum, and maximum of three integers

Getting Started

Requirements

  • A C compiler (GCC or Clang)
  • A terminal (Linux, macOS, or Windows)

Installation

Clone the repository:

git clone https://github.com/Fai707/C-TextKit.git
cd C-TextKit

Compile the programs using GCC:

gcc -Wall -Wextra trimcli.c -o trimcli
gcc -Wall -Wextra bufcopy.c -o bufcopy
gcc -Wall -Wextra argsplit.c -o argsplit
gcc -Wall -Wextra replacecli.c -o replacecli
gcc -Wall -Wextra heapstats.c -o heapstats

Usage

1. trimcli — Whitespace Trimming

Removes unnecessary whitespace from text.

./trimcli "   Hello World   "

Options:

./trimcli --left "   Hello World   "
./trimcli --right "   Hello World   "
  • --left removes leading whitespace.
  • --right removes trailing whitespace.
  • Without an option, whitespace is removed from both ends.

2. bufcopy — Bounded String Copy

Copies a string into a buffer while respecting a specified capacity.

./bufcopy 6 "Hello World"

Output:

[Hello]
length: 5
truncated: yes

The program reserves space for the null terminator (\0) and reports whether the original string was truncated.

Capacity must be between 1 and 256.

3. argsplit — Argument Splitting

Splits a string into separate arguments using spaces and tabs as delimiters.

./argsplit "hello world from C"

Output:

argc: 4
argv[0]: [hello]
argv[1]: [world]
argv[2]: [from]
argv[3]: [C]

Current limitations:

  • Maximum input length: 255 characters.
  • Maximum number of arguments: 15.
  • Does not implement shell-style quoting or escaping.

4. replacecli — String Replacement

Replaces text within an input string.

Syntax:

./replacecli "text" from to

Example:

./replacecli "hello world" world Linux

5. heapstats — Integer Statistics

Reads three integers from standard input and calculates their sum, maximum, and minimum.

./heapstats

Example input:

10 20 30

Output:

sum: 60
max: 30
min: 10

Despite its name, the current implementation focuses on integer operations rather than heap memory statistics.

Concepts Practiced

This project explores several fundamental C programming concepts:

  • Pointers and pointer arithmetic: Traversing and modifying character arrays.
  • String manipulation: Working with null-terminated strings.
  • Buffer management: Handling fixed-size buffers and preventing out-of-bounds writes.
  • Command-line arguments: Processing argc and argv.
  • Input validation: Checking argument counts and accepted input ranges.
  • Control flow: Implementing algorithms using loops and conditional statements.
  • Functions: Separating operations into reusable pieces of code.

Repository Structure

C-TextKit/
├── argsplit.c
├── bufcopy.c
├── heapstats.c
├── replacecli.c
├── trimcli.c
├── .gitignore
└── README.md

Each utility is implemented as an independent C program and can be compiled separately.

Project Goals

The main goal of C-TextKit is to develop a stronger foundation in low-level programming.

By building these utilities, I aim to improve my understanding of memory, pointers, string processing, and the design of command-line applications.

These concepts provide a foundation for more advanced projects involving Linux system programming, memory management, and operating systems.

Author

Fai707

GitHub: github.com/Fai707

About

A collection of string manipulation tools in C

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages