Just trying to do toy exercises to get my head around the language. Any idea why I'm getting error: expected type '[]const u8', found 'error{NoSpaceLeft}' at comptime on line 14, I need to return the argument n as a string in the buffer. Also if anyone can advise on working with strings in general, I'm cobbling this together from Google (the exercise wants a buffer filled for some reason, but it'd be nice to do some elegant concatenation I guess)
const std = @import("std");
pub fn main() !void
{
var input: [15]u8 = [_]u8{0} ** 15;
const ip = convert(&input, 15);
std.debug.print("{s}", .{ip});
}
pub fn convert(buffer: []u8, n: u32) []const u8
{
if (n % 3 == 0 and n % 5 == 0 and n % 7 == 0)
{
try std.fmt.bufPrint(buffer, "{d}", .{ n });
return buffer;
}
if (n % 3 == 0) @memmove(buffer[0..5], "Pling");
if (n % 5 == 0) @memmove(buffer[5..10], "Plang");
if (n % 7 == 0) @memmove(buffer[10..], "Plong");
return buffer;
}