01_hello.zig 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. // Oh no! This program is supposed to print "Hello world!" but it has some
  2. // mistakes. Let's fix it.
  3. //
  4. // We're trying to import the Standard Library into the top level of our
  5. // application. The standard library is not named "foo", it is named "std".
  6. //
  7. // Please correct the name in both places in the import here:
  8. const foo = @import("foo");
  9. // Zig applications start by calling a function named 'main'. It needs to be
  10. // public so that it is accessible outside our file!
  11. //
  12. // Public functions are declared with the 'pub' keyword like so:
  13. //
  14. // pub fn my_function() void { ... }
  15. //
  16. // Please make the main() function public:
  17. fn main() void {
  18. // The easiest way to display our "Hello world" message in the
  19. // terminal is to use the std.debug.print() function.
  20. // Please fix this silly "foo" mistake here:
  21. foo.debug.print("Hello world!\n", .{});
  22. // The print function above takes two values:
  23. //
  24. // 1. A string of characters: "Hello world!\n". "\n" prints a new line.
  25. //
  26. // 2. A struct containing data to be displayed. .{} is an empty, nameless
  27. // struct fulfilling the requirement. More about structs later.
  28. //
  29. //
  30. // Now we're ready to...What's this!? Oh, we wanted to print a Goodbye
  31. // message as well!
  32. //
  33. // Please fix this to use the same print function as above:
  34. "Goodbye!\n"
  35. }
  36. // Once you're done with the changes above, run `ziglings` to see if it passes.
  37. //
  38. // Finally, all files will contain the following comment:
  39. //
  40. // I AM NOT DONE
  41. //
  42. // Delete it when you're ready to continue to the next exercise!