Problem about converting from slice to sentinal terminated slice

Use std.fmt.allocPrintZ
for future reference:

  • Allocator.dupeZ, or Allocator.allocSentinal if you want a non zero terminator
  • you can also slice[a..b :0], to make a slice with a sentinel from a non sentinel slice, note that zig will not set the actual value after the slice to the sentinal, but will (in safe builds) assert that it is already set correctly, so set it before you convert to a terminated slice.
  • @ptrCast should be avoided, but does work
3 Likes