Created
July 29, 2020 00:58
-
-
Save lithdew/7ce0dd2d344516dccf600a1f4ff2dbad to your computer and use it in GitHub Desktop.
zig concat
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const std = @import("std"); | |
pub fn concat(bufs: []const []const u8) ![]const u8 { | |
// var buf: [11]u8 = undefined; | |
// var buffer = std.heap.FixedBufferAllocator.init(&buf); | |
return std.mem.concat(std.heap.c_allocator, u8, bufs); | |
// return std.mem.concat(&buffer.allocator, u8, bufs); | |
} | |
pub fn main() !void { | |
var first = try concat(&[_][]const u8{ "hello ", "world" }); | |
defer std.heap.c_allocator.free(first); | |
std.debug.print("{}\n", .{first}); | |
var sec = try concat(&[_][]const u8{ "test ", "two" }); | |
defer std.heap.c_allocator.free(sec); | |
std.debug.print("{} {}\n", .{ first, sec }); | |
var thir = try concat(&[_][]const u8{ "xxxx ", "yyyyy" }); | |
defer std.heap.c_allocator.free(thir); | |
std.debug.print("{} {} {}\n", .{ first, sec, thir }); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment