Skip to content

Instantly share code, notes, and snippets.

@nick133
Created October 22, 2025 22:58
Show Gist options
  • Select an option

  • Save nick133/392038169d8f9fc9011730bda3ffe483 to your computer and use it in GitHub Desktop.

Select an option

Save nick133/392038169d8f9fc9011730bda3ffe483 to your computer and use it in GitHub Desktop.
printf() for Zig
//
// Reliable C printf() replacement
// Zig version 0.16.0-dev.747+493ad58ff
//
const std = @import("std");
fn printf(comptime fmt: []const u8, args: anytype) !void {
var buf: [128]u8 = undefined;
// Create a buffered writer for stdout using the buffer
var fw = std.fs.File.stdout().writer(&buf);
const writer: *std.Io.Writer = &fw.interface;
try writer.print(fmt, args);
try writer.flush();
}
pub fn main() !void {
try printf("Hello, {s}! The answer is {d}\n", .{"Zig", 42});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment