#printing not working properly [0.13.0]

1 messages · Page 1 of 1 (latest)

next patrol
#

The code:

const std = @import("std");
const print = std.debug.print;

const TITLE = "Simple-Calculator";

fn getNumberInput(statement: []const u8) ![]u8 {
    var input: [1024]u8 = undefined;

    print("{s} ", .{statement});

    const result = try std.io.getStdIn().reader().readUntilDelimiter(&input, '\n');
    return result;
}

pub fn main() !void {
    print("================================\n-|Welcome To {s}|-\n================================\n", .{TITLE});
    
    const firstNumber = try getNumberInput("Enter your first number:");

    print("You entered: {s}!\n", .{firstNumber});
}

The output:

================================
-|Welcome To Simple-Calculator|-
================================
Enter your first number: 88
You entered: ��!
honest sun
#

i think either do everything you need to and return a number or accept a destination slice into getNumberInput

deft oracle
# next patrol **The code:** ```py const std = @import("std"); const print = std.debug.print; ...

Further reading so you will remember next time 🙂 (at least for the stack case which is easier to not do)

https://en.m.wikipedia.org/wiki/Dangling_pointer

Dangling pointers and wild pointers in computer programming are pointers that do not point to a valid object of the appropriate type. These are special cases of memory safety violations. More generally, dangling references and wild references are references that do not resolve to a valid destination.
Dangling pointers arise during object destruc...

next patrol