mirror of
https://codeberg.org/ziglings/exercises.git
synced 2024-12-26 01:20:30 +00:00
Added string specifier in format strings (#3)
This is now required in current versions of Zig.
This commit is contained in:
parent
56ba5d7fda
commit
2bdacd35c1
3 changed files with 8 additions and 7 deletions
|
@ -35,11 +35,12 @@ pub fn main() void {
|
||||||
// That's all the problems. Let's see our results:
|
// That's all the problems. Let's see our results:
|
||||||
std.debug.print("d={u} {s}{s}\n",.{d, laugh, major_tom});
|
std.debug.print("d={u} {s}{s}\n",.{d, laugh, major_tom});
|
||||||
//
|
//
|
||||||
// Keen eyes will notice that we've put a 'u' inside the '{}'
|
// Keen eyes will notice that we've put 'u' and 's' inside the '{}'
|
||||||
// placeholder in the format string above. This tells the
|
// placeholders in the format string above. This tells the
|
||||||
// print() function to format the values as a UTF-8 character.
|
// print() function to format the values as a UTF-8 character and
|
||||||
// If we didn't do this, we'd see '100', which is the decimal
|
// UTF-8 strings respectively. If we didn't do this, we'd see '100',
|
||||||
// number corresponding with the 'd' character in UTF-8.
|
// which is the decimal number corresponding with the 'd' character
|
||||||
|
// in UTF-8. (And an error in the case of the strings.)
|
||||||
//
|
//
|
||||||
// While we're on this subject, 'c' (ASCII encoded character)
|
// While we're on this subject, 'c' (ASCII encoded character)
|
||||||
// would work in place for 'u' because the first 128 characters
|
// would work in place for 'u' because the first 128 characters
|
||||||
|
|
|
@ -20,5 +20,5 @@ pub fn main() void {
|
||||||
And the Spiders from Mars
|
And the Spiders from Mars
|
||||||
;
|
;
|
||||||
|
|
||||||
std.debug.print("{}\n",.{lyrics});
|
std.debug.print("{s}\n",.{lyrics});
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,5 +30,5 @@ pub fn main() void {
|
||||||
lang[2] = letters[???];
|
lang[2] = letters[???];
|
||||||
|
|
||||||
// We want to "Program in Zig!" of course:
|
// We want to "Program in Zig!" of course:
|
||||||
std.debug.print("Program in {}!\n", .{lang});
|
std.debug.print("Program in {s}!\n", .{lang});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue