zig-cli/util.zig

19 lines
412 B
Zig

const std = @import("std");
const testing = std.testing;
const stdlib = @cImport({
@cInclude("stdlib.h");
});
pub fn strToFloat(str: [*c]const u8) f32 {
return @floatCast(stdlib.atof(str));
}
pub fn strToInt(str: [*c]const u8) i32 {
return @intCast(stdlib.atoi(str));
}
test "string cast to number" {
try testing.expect(3 == strToInt("3"));
try testing.expect(3.2 == strToFloat("3.2"));
}