std/io

March 14, 2026 ยท View on GitHub

The std/io module provides standard input/output functionality, including formatted printing to stdout and robust reading from stdin.

Overview

  • Formatted Output: Provides print and println with support for C-style format specifiers (%s, %d, etc.).
  • String Formatting: Multiple options for formatting into static, user-provided, or heap-allocated buffers.
  • Unicode Aware: Includes read_rune for reading individual UTF-8 characters from stdin.
  • Conversion Utilities: Simple methods for converting integers and runes to strings.

Usage

import "std/io.zc"

fn main() {
    // Basic printing
    println("Hello, %s!", "Zen-C");
    
    // Reading a line of input
    print("Enter your name: ");
    autofree let name = readln();
    
    if name != NULL {
        println("Greeting, %s", name);
    }
}

Methods

Output

MethodSignatureDescription
printprint(fmt: char*, ...) -> intPrints formatted output to stdout.
printlnprintln(fmt: char*, ...) -> intPrints formatted output to stdout followed by a newline.

Input

MethodSignatureDescription
readlnreadln() -> char*Reads a line from stdin. Returns a heap-allocated string (caller must free).
read_runeread_rune() -> runeReads a single UTF-8 character (rune) from stdin.

Formatting

MethodSignatureDescription
formatformat(fmt: char*, ...) -> char*Formats into a internal static buffer. Warning: Not thread-safe.
format_intoformat_into(buf: char*, size: usize, fmt: char*, ...) -> intFormats into a user-provided buffer of specific size.
format_newformat_new(fmt: char*, ...) -> char*Formats into a new heap-allocated buffer. Caller must free.

Conversion

MethodSignatureDescription
itositos(n: int) -> char*Converts n to a string in a static buffer.
itos_newitos_new(n: int) -> char*Converts n to a heap-allocated string.
utosutos(n: uint) -> char*Converts unsigned n to a string in a static buffer.