std/io

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

Overview

Usage

import "std/io.zc"

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

Methods

Output

MethodSignatureDescription
printprint(s: const char*)Prints s to stdout.
printlnprintln(s: const char*)Prints s to stdout followed by a newline.
eprinteprint(s: const char*)Prints s to stderr.
eprintlneprintln(s: const char*)Prints s to stderr 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 thread-local buffer. A ring of buffers makes nested format() calls safe; each returned pointer stays valid until 4 further format() calls on the same thread.
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.