diff options
author | Dave Gauer <dave@ratfactor.com> | 2021-02-10 22:13:22 -0500 |
---|---|---|
committer | Dave Gauer <dave@ratfactor.com> | 2021-02-10 22:13:22 -0500 |
commit | bb5c219daec42be742e81f726ebdcfae4219e084 (patch) | |
tree | 549692ef98bff9eefacd7a6ade3487a5cab8f81c | |
parent | d50aa3577b30b67691e0ec60c3219821b88de641 (diff) | |
download | ziglings-bb5c219daec42be742e81f726ebdcfae4219e084.tar.gz ziglings-bb5c219daec42be742e81f726ebdcfae4219e084.tar.bz2 ziglings-bb5c219daec42be742e81f726ebdcfae4219e084.tar.xz ziglings-bb5c219daec42be742e81f726ebdcfae4219e084.zip |
Added string specifier in format strings (#3)
This is now required in current versions of Zig.
-rw-r--r-- | exercises/06_strings.zig | 11 | ||||
-rw-r--r-- | exercises/07_strings2.zig | 2 | ||||
-rw-r--r-- | exercises/08_quiz.zig | 2 |
3 files changed, 8 insertions, 7 deletions
diff --git a/exercises/06_strings.zig b/exercises/06_strings.zig index d469166..1d3da1a 100644 --- a/exercises/06_strings.zig +++ b/exercises/06_strings.zig @@ -35,11 +35,12 @@ pub fn main() void { // That's all the problems. Let's see our results: std.debug.print("d={u} {s}{s}\n",.{d, laugh, major_tom}); // - // Keen eyes will notice that we've put a 'u' inside the '{}' - // placeholder in the format string above. This tells the - // print() function to format the values as a UTF-8 character. - // If we didn't do this, we'd see '100', which is the decimal - // number corresponding with the 'd' character in UTF-8. + // Keen eyes will notice that we've put 'u' and 's' inside the '{}' + // placeholders in the format string above. This tells the + // print() function to format the values as a UTF-8 character and + // UTF-8 strings respectively. If we didn't do this, we'd see '100', + // 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) // would work in place for 'u' because the first 128 characters diff --git a/exercises/07_strings2.zig b/exercises/07_strings2.zig index bb81bc7..f0bbf99 100644 --- a/exercises/07_strings2.zig +++ b/exercises/07_strings2.zig @@ -20,5 +20,5 @@ pub fn main() void { And the Spiders from Mars ; - std.debug.print("{}\n",.{lyrics}); + std.debug.print("{s}\n",.{lyrics}); } diff --git a/exercises/08_quiz.zig b/exercises/08_quiz.zig index e23f856..eda66b8 100644 --- a/exercises/08_quiz.zig +++ b/exercises/08_quiz.zig @@ -30,5 +30,5 @@ pub fn main() void { lang[2] = letters[???]; // We want to "Program in Zig!" of course: - std.debug.print("Program in {}!\n", .{lang}); + std.debug.print("Program in {s}!\n", .{lang}); } |