aboutsummaryrefslogtreecommitdiff
path: root/01_hello.zig
diff options
context:
space:
mode:
authorDave Gauer <dave@ratfactor.com>2020-12-23 12:02:35 -0500
committerDave Gauer <dave@ratfactor.com>2020-12-23 13:53:27 -0500
commit3b5678815f010bd016ca561e4672d2d83271cb2e (patch)
tree5d6bf2c6adcc6846c81a087dcd2596430230131a /01_hello.zig
downloadziglings-3b5678815f010bd016ca561e4672d2d83271cb2e.tar.gz
ziglings-3b5678815f010bd016ca561e4672d2d83271cb2e.tar.bz2
ziglings-3b5678815f010bd016ca561e4672d2d83271cb2e.tar.xz
ziglings-3b5678815f010bd016ca561e4672d2d83271cb2e.zip
Initial commit with readme, script, and hello world
Absolutely minimum viable stuff.
Diffstat (limited to '01_hello.zig')
-rw-r--r--01_hello.zig47
1 files changed, 47 insertions, 0 deletions
diff --git a/01_hello.zig b/01_hello.zig
new file mode 100644
index 0000000..a77d919
--- /dev/null
+++ b/01_hello.zig
@@ -0,0 +1,47 @@
+// Oh no! This program is supposed to print "Hello world!" but it has some
+// mistakes. Let's fix it.
+//
+// We're trying to import the Standard Library into the top level of our
+// application. The standard library is not named "foo", it is named "std".
+//
+// Please correct the name in both places in the import here:
+const foo = @import("foo");
+
+// Zig applications start by calling a function named 'main'. It needs to be
+// public so that it is accessible outside our file!
+//
+// Public functions are declared with the 'pub' keyword like so:
+//
+// pub fn my_function() void { ... }
+//
+// Please make the main() function public:
+fn main() void {
+
+ // The easiest way to display our "Hello world" message in the
+ // terminal is to use the std.debug.print() function.
+
+ // Please fix this silly "foo" mistake here:
+ foo.debug.print("Hello world!\n", .{});
+
+ // The print function above takes two values:
+ //
+ // 1. A string of characters: "Hello world!\n". "\n" prints a new line.
+ //
+ // 2. A struct containing data to be displayed. .{} is an empty, nameless
+ // struct fulfilling the requirement. More about structs later.
+ //
+ //
+ // Now we're ready to...What's this!? Oh, we wanted to print a Goodbye
+ // message as well!
+ //
+ // Please fix this to use the same print function as above:
+ "Goodbye!\n"
+}
+
+// Once you're done with the changes above, run `ziglings` to see if it passes.
+//
+// Finally, all files will contain the following comment:
+//
+// I AM NOT DONE
+//
+// Delete it when you're ready to continue to the next exercise!