Skip to content

Ade20boss/c-lowlevel-labs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

C Low-Level Labs 🛠️

A collection of C programs exploring system fundamentals, pointer arithmetic, state machines, and manual memory management. This repository focuses on understanding how high-level abstractions (like Python's .split() or int()) work under the hood.

📂 The Programs

1. Stream Auditor (stream_auditor.c)

Concepts: Finite State Machines (FSM), Buffered I/O, Stream Transducers. A Unix-style utility that functions as both a wc (Word Count) clone and a stream formatter.

  • Uses O(1) memory complexity (processes streams of infinite size).
  • Implements a State Machine (IN/OUT) to handle tokenization.
  • Delivers real-time statistical analysis.

2. Manual String Tokenizer (word_tokenizer_array.c)

Concepts: Arrays, Buffers, Two-Pass Processing. A text parser that reads input into a stack-allocated buffer and reformats it to "one word per line."

  • Demonstrates the trade-offs of buffer-based processing vs. stream processing.
  • Includes overflow protection logic.

3. Shipping Calculator (shipping_calculator.c)

Concepts: Symbolic Constants, Manual Integer Parsing, Logic Flow. A logistics pricing tool that calculates costs based on weight tiers.

  • Key Feature: Does not use scanf. Implements a custom loop to parse ASCII input digits into integers manually.
  • Applies symbolic constants for maintainable business logic (Heavy Fees, Limits).

4. ASCII to Integer Converter (ascii_to_int.c)

Concepts: ASCII Arithmetic, Data Representation. A raw implementation of the standard atoi() function.

  • Reads character bytes and mathematically converts them to their integer equivalents.
  • Demonstrates how computers understand numbers vs. text.

5. Manual String Length (manual_strlen.c)

Concepts: Pointers, Memory Addressing. Recreating the strlen function using pointer arithmetic.

  • Avoids array indexing (i++).
  • Directly manipulates memory addresses (s++) to traverse the string segment.

6. Manual Integer Parser in C 🛠️

A low-level exploration of standard library functions. This project recreates the logic of scanf from scratch to understand stream I/O, ASCII conversion, and pointer manipulation.

How It Works

Instead of using the standard scanf("%d"), I built a custom parser (my_scanf) that:

  1. Manages the Input Stream: Uses getchar() to read standard input byte-by-byte.
  2. Handles Whitespace: Manually skips spaces, tabs, and newlines.
  3. Performs ASCII Math: Converts character data into integer types (e.g., '5' -> 5).
  4. Uses Pointers: Modifies variables in the calling function via memory addresses (Pass-by-Reference).

The Logic

The core conversion logic uses a standard algorithm:

total = (total * 10) + (char - '0');

🚀 How to Run

Compile any file using GCC:

gcc stream_auditor.c -o auditor
./auditor

About

Implementing core system utilities and algorithms from scratch in C. Features manual memory management, finite state machines, and raw stream processing without high-level abstractions.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages