I am trying to make a sort of input() function for a project I've been working on.
The function simply reads from stdin and returns the string.
Here's what I came up with:
const std = @import("std");
pub fn input_expression() ![]u8 {
const stdin = std.io.getStdIn().reader();
var buf: [32]u8 = undefined;
const result = stdin.readUntilDelimiterOrEof(buf[0..], '\n') catch |err| {
return err;
};
if (result == null) {
return error.NoData;
}
std.debug.print("result: {s}\n", .{result.?});
return result.?;
}
This is placed inside an external module called interface.zig.
Inside of main, I import interface.zig:
const std = @import("std");
const interface = @import("interface.zig");
pub fn main() !void {
const expr: []u8 = try interface.input_expression();
std.debug.print("expr: {s}\n", .{expr});
}
I would expect the output from 'inside' the function (meaning the std.debug.print(result: {}) inside of it) to be the same as the output of main.
Instead here is the output
205 + 2 (Input)
result: 205 + 2
expr: ��#8�