Added Ex. 2, polished script, added LICENSE
This commit is contained in:
parent
3b5678815f
commit
d618414c9c
5 changed files with 101 additions and 93 deletions
51
01_hello.zig
51
01_hello.zig
|
|
@ -1,47 +1,16 @@
|
|||
// 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".
|
||||
// Oh no! This program is supposed to print "Hello world!" but it needs
|
||||
// your help!
|
||||
//
|
||||
// Please correct the name in both places in the import here:
|
||||
const foo = @import("foo");
|
||||
// Hint: Zig functions are private by default.
|
||||
// The main() function should be public.
|
||||
// Declare a public function with "pub fn ..."
|
||||
//
|
||||
// Try to fix the program and run `ziglings` to see if it passes.
|
||||
//
|
||||
const std = @import("std");
|
||||
|
||||
// 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"
|
||||
std.debug.print("Hello world!\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!
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue