From f73df8d5de30a7f3f320fccf5f57c13094940a6a Mon Sep 17 00:00:00 2001 From: Zuhaitz Méndez Fernández de Aránguiz Date: Fri, 23 Jan 2026 12:22:57 +0000 Subject: Variadic functions + more docs --- docs/std/io.md | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 docs/std/io.md (limited to 'docs/std/io.md') diff --git a/docs/std/io.md b/docs/std/io.md new file mode 100644 index 0000000..825728d --- /dev/null +++ b/docs/std/io.md @@ -0,0 +1,44 @@ +# Standard Library: IO (`std/io.zc`) + +The `std/io` module provides standard input/output functionality, including printing to stdout and reading from stdin. + +## Usage + +```zc +import "std/io.zc" + +fn main() { + // Printing + io.println("Hello %s", "World"); + + // Formatting strings + autofree var s = io.format_new("Value: %d", 42); + + // Reading input + io.print("Enter name: "); + autofree var name = io.readln(); +} +``` + +## Functions + +### Output + +| Function | Signature | Description | +| :--- | :--- | :--- | +| **print** | `print(fmt: char*, ...) -> int` | Prints formatted output to stdout. | +| **println** | `println(fmt: char*, ...) -> int` | Prints formatted output to stdout with a newline. | + +### Formatting + +| Function | Signature | Description | +| :--- | :--- | :--- | +| **format** | `format(fmt: char*, ...) -> char*` | Formats string into a static buffer (returns pointer). **Not thread-safe**. | +| **format_into** | `format_into(buf: char*, size: usize, fmt: char*, ...) -> int` | Formats string into a user-provided buffer. | +| **format_new** | `format_new(fmt: char*, ...) -> char*` | Formats string into a newly allocated buffer (caller must free). | + +### Input + +| Function | Signature | Description | +| :--- | :--- | :--- | +| **readln** | `readln() -> char*` | Reads a line from stdin. Returns heap-allocated string (caller must free) or `NULL` on EOF/error. | -- cgit v1.2.3