This commit is contained in:
2026-06-05 23:51:45 +02:00
parent 629634e09d
commit a5bbd016eb
7 changed files with 16 additions and 7 deletions
+1 -1
View File
@@ -14,7 +14,7 @@ pub fn main(init: std.process.Init) !void {
var stdout_writer = std.Io.File.stdout().writer(io, &.{});
const stdout = &stdout_writer.interface;
const my_num: u32 = getNumber();
const my_num: u32 = try getNumber();
try stdout.print("my_num={}\n", .{my_num});
}
+1 -1
View File
@@ -20,7 +20,7 @@
const std = @import("std");
// Please complete the enum!
const Ops = enum { ??? };
const Ops = enum { inc, dec, pow };
pub fn main() void {
const operations = [_]Ops{
+3 -3
View File
@@ -31,7 +31,7 @@ const std = @import("std");
const Color = enum(u32) {
red = 0xff0000,
green = 0x00ff00,
blue = ???,
blue = 0x0000ff,
};
pub fn main() void {
@@ -53,12 +53,12 @@ pub fn main() void {
\\<p>
\\ <span style="color: #{x:0>6}">Red</span>
\\ <span style="color: #{x:0>6}">Green</span>
\\ <span style="color: #{}">Blue</span>
\\ <span style="color: #{x:0>6}">Blue</span>
\\</p>
\\
, .{
@intFromEnum(Color.red),
@intFromEnum(Color.green),
@intFromEnum(???), // Oops! We're missing something!
@intFromEnum(Color.blue), // Oops! We're missing something!
});
}
+2
View File
@@ -36,6 +36,7 @@ const Character = struct {
role: Role,
gold: u32,
experience: u32,
health: u8,
};
pub fn main() void {
@@ -44,6 +45,7 @@ pub fn main() void {
.role = Role.wizard,
.gold = 20,
.experience = 10,
.health = 100,
};
// Glorp gains some gold.
+7
View File
@@ -43,6 +43,13 @@ pub fn main() void {
// Feel free to run this program without adding Zump. What does
// it do and why?
chars[1] = Character{
.role = Role.bard,
.gold = 10,
.health = 100,
.experience = 20,
};
// Printing all RPG characters in a loop:
for (chars, 0..) |c, num| {
std.debug.print("Character {} - G:{} H:{} XP:{}\n", .{
+1 -1
View File
@@ -30,7 +30,7 @@ pub fn main() void {
// Please make num2 equal 5 using num1_pointer!
// (See the "cheatsheet" above for ideas.)
num2 = ???;
num2 = num1_pointer.*;
std.debug.print("num1: {}, num2: {}\n", .{ num1, num2 });
}
+1 -1
View File
@@ -23,7 +23,7 @@ const std = @import("std");
pub fn main() void {
const a: u8 = 12;
const b: *u8 = &a; // fix this!
const b: *const u8 = &a; // fix this!
std.debug.print("a: {}, b: {}\n", .{ a, b.* });
}