diff --git a/exercises/acronym/src/example.h b/exercises/acronym/src/acronym.h similarity index 100% rename from exercises/acronym/src/example.h rename to exercises/acronym/src/acronym.h diff --git a/exercises/gigasecond/.meta/hints.md b/exercises/gigasecond/.meta/hints.md new file mode 100644 index 000000000..0197ca392 --- /dev/null +++ b/exercises/gigasecond/.meta/hints.md @@ -0,0 +1,124 @@ +## Exercises without stub implementations + +Like the majority of C programs you will write, this exercise comes without any header file (`*.h`) or source file (`*.c`). + + +### Add the required files + +You will need to create these yourself as part of the exercise. +This is so that you get to practice deciding on and creating the program's interface yourself, which is an important part of programming in C. +It does mean that when you first try to run the tests, they won't compile. +They will give you an error similar to: + +```bash +make: *** No rule to make target 'src/exercise_name.c', needed by 'tests.out'. Stop. +``` + +This error occurs because the `makefile` attempts to use a file that hasn't been created yet (`exercise_name.c`). +To resolve this error you will need to add a matching file to the `src` directory. +For example, for the error above you would add a file called `exercise_name.c`. + +When you try to run the tests again you will get a slightly different error. + +```bash +make: *** No rule to make target 'src/exercise_name.h', needed by 'tests.out'. Stop. +``` + +Again the `makefile` still needs another file that has yet to be created (`exercise_name.h`). +The solution to this error is similar to the last, add the matching file to the `src` directory. +For example, for the above error you would add a file called `exercise_name.h` + + +### Add the required declarations + +Running the tests a third time you see you will get new errors, similar to: + +```bash +Compiling tests.out +src/exercise_name.c:1:0: error: ISO C forbids an empty translation unit [-Werror=pedantic] +cc1: all warnings being treated as errors +test/test_exercise_name.c:13:1: error: unknown type name ‘bar_t’; did you mean ‘__bar_t’? + bar_t b = foo(a, 2.5); + ^~~~~~ + __bar_t +test/test_exercise_name.c:15:14: error: storage size of fizz isn’t known + struct baz fizz; + ^~~~ +test/test_exercise_name.c:29:20: error: implicit declaration of function ‘foo’ [-Werror=implicit-function-declaration] + bar_t b = foo_function(fizz, 2.5); +``` + +This error means that you need to add function, type and variable decarations to the header file to match those the test file is attempting to use. +In doing this you will need to look at the build errors and the test code to determine what needs to be declared in the header file. + +For example, for the error above you should declare a type named `bar_t`, a `struct` called `baz` and a function named `foo()`. +Additionally we can tell from looking at the above errors that function `foo()` has two parameters. + +The first parameter is passed an argument of `fizz` and thus should have a type of `struct baz`. +The second parameter is passed `2.5` and so could have one of two types, either `float` or `double`. +You will need to look at the test code to determine which. + +The _names_ of the parameters are not determined by the test code and so are left up to you to decide, though in keeping with C programming practices they should be descriptive but not overly long. + +Further, we can see that the the return type expected by the test code is of the type `bar_t`. + +Putting this all together we end up with a function declaration that looks like the following: + +```c +// The parameter names are not very good here they should be more descriptive in a real exercise. +// We have decide on a double for the second parameter in this hypothetical example. +bar_t foo(struct baz b, double d); +``` + +You should continue to do this for any further similar errors. +To check that you have correctly determined the required declaration, just run the tests again and analyse any errors similarly. + +Additionally, remember to add any includes to the header file any headers that it itself requires. + + +### Include guards + +Before you are finished with the header file, you should add include guards. +Include guards are used to help prevent the file from being included multiple times by accident. +If the file _was_ included multiple times then the functions and other items would be declared twice; In C this is an error because the compiler thinks you are trying to declare another _different_ function that has the same name. + +To add include guards, add something similar to the following as the first two lines of the header: + +```c +#ifndef EXERCISE_NAME_H +#define EXERCISE_NAME_H +``` + +And on the very last line: + +```c +#endif +``` + + +### Add the required definitions + +Once the header file is complete you may still have build errors similar to the following: + +```bash +Compiling tests.out +src/exercise_name.c:1:0: error: ISO C forbids an empty translation unit [-Werror=pedantic] +cc1: all warnings being treated as errors +makefile:24: recipe for target 'tests.out' failed +make: *** [tests.out] Error 1 +``` + +This is because although you have _declared_ all the items you need to, they have not yet been _defined_. +To define the needed items you need to add their implementation to the `exercise_name.c` file. +For the function `foo()` from the previous example, this would look similar to: + +```c +#include "exercise_name.h" + +bar_t foo(struct baz b, double d) +{ + // Your exercise code here +} +``` + +After having resolved these errors you should be ready to start making the tests pass! diff --git a/exercises/gigasecond/README.md b/exercises/gigasecond/README.md index 6be7cfbe4..244de13bc 100644 --- a/exercises/gigasecond/README.md +++ b/exercises/gigasecond/README.md @@ -4,6 +4,132 @@ Calculate the moment when someone has lived for 10^9 seconds. A gigasecond is 10^9 (1,000,000,000) seconds. +## Exercises without stub implementations + +Like the majority of C programs you will write, this exercise comes without any header file (`*.h`) or source file (`*.c`). + + +### Add the required files + +You will need to create these yourself as part of the exercise. +This is so that you get to practice deciding on and creating the program's interface yourself, which is an important part of programming in C. +It does mean that when you first try to run the tests, they won't compile. +They will give you an error similar to: + +```bash +make: *** No rule to make target 'src/exercise_name.c', needed by 'tests.out'. Stop. +``` + +This error occurs because the `makefile` attempts to use a file that hasn't been created yet (`exercise_name.c`). +To resolve this error you will need to add a matching file to the `src` directory. +For example, for the error above you would add a file called `exercise_name.c`. + +When you try to run the tests again you will get a slightly different error. + +```bash +make: *** No rule to make target 'src/exercise_name.h', needed by 'tests.out'. Stop. +``` + +Again the `makefile` still needs another file that has yet to be created (`exercise_name.h`). +The solution to this error is similar to the last, add the matching file to the `src` directory. +For example, for the above error you would add a file called `exercise_name.h` + + +### Add the required declarations + +Running the tests a third time you see you will get new errors, similar to: + +```bash +Compiling tests.out +src/exercise_name.c:1:0: error: ISO C forbids an empty translation unit [-Werror=pedantic] +cc1: all warnings being treated as errors +test/test_exercise_name.c:13:1: error: unknown type name ‘bar_t’; did you mean ‘__bar_t’? + bar_t b = foo(a, 2.5); + ^~~~~~ + __bar_t +test/test_exercise_name.c:15:14: error: storage size of fizz isn’t known + struct baz fizz; + ^~~~ +test/test_exercise_name.c:29:20: error: implicit declaration of function ‘foo’ [-Werror=implicit-function-declaration] + bar_t b = foo_function(fizz, 2.5); +``` + +This error means that you need to add function, type and variable decarations to the header file to match those the test file is attempting to use. +In doing this you will need to look at the build errors and the test code to determine what needs to be declared in the header file. + +For example, for the error above you should declare a type named `bar_t`, a `struct` called `baz` and a function named `foo()`. +Additionally we can tell from looking at the above errors that function `foo()` has two parameters. + +The first parameter is passed an argument of `fizz` and thus should have a type of `struct baz`. +The second parameter is passed `2.5` and so could have one of two types, either `float` or `double`. +You will need to look at the test code to determine which. + +The _names_ of the parameters are not determined by the test code and so are left up to you to decide, though in keeping with C programming practices they should be descriptive but not overly long. + +Further, we can see that the the return type expected by the test code is of the type `bar_t`. + +Putting this all together we end up with a function declaration that looks like the following: + +```c +// The parameter names are not very good here they should be more descriptive in a real exercise. +// We have decide on a double for the second parameter in this hypothetical example. +bar_t foo(struct baz b, double d); +``` + +You should continue to do this for any further similar errors. +To check that you have correctly determined the required declaration, just run the tests again and analyse any errors similarly. + +Additionally, remember to add any includes to the header file any headers that it itself requires. + + +### Include guards + +Before you are finished with the header file, you should add include guards. +Include guards are used to help prevent the file from being included multiple times by accident. +If the file _was_ included multiple times then the functions and other items would be declared twice; In C this is an error because the compiler thinks you are trying to declare another _different_ function that has the same name. + +To add include guards, add something similar to the following as the first two lines of the header: + +```c +#ifndef EXERCISE_NAME_H +#define EXERCISE_NAME_H +``` + +And on the very last line: + +```c +#endif +``` + + +### Add the required definitions + +Once the header file is complete you may still have build errors similar to the following: + +```bash +Compiling tests.out +src/exercise_name.c:1:0: error: ISO C forbids an empty translation unit [-Werror=pedantic] +cc1: all warnings being treated as errors +makefile:24: recipe for target 'tests.out' failed +make: *** [tests.out] Error 1 +``` + +This is because although you have _declared_ all the items you need to, they have not yet been _defined_. +To define the needed items you need to add their implementation to the `exercise_name.c` file. +For the function `foo()` from the previous example, this would look similar to: + +```c +#include "exercise_name.h" + +bar_t foo(struct baz b, double d) +{ + // Your exercise code here +} +``` + +After having resolved these errors you should be ready to start making the tests pass! + + ## Getting Started Make sure you have read the diff --git a/exercises/isogram/src/example.h b/exercises/isogram/src/isogram.h similarity index 100% rename from exercises/isogram/src/example.h rename to exercises/isogram/src/isogram.h diff --git a/exercises/meetup/.meta/hints.md b/exercises/meetup/.meta/hints.md new file mode 100644 index 000000000..0197ca392 --- /dev/null +++ b/exercises/meetup/.meta/hints.md @@ -0,0 +1,124 @@ +## Exercises without stub implementations + +Like the majority of C programs you will write, this exercise comes without any header file (`*.h`) or source file (`*.c`). + + +### Add the required files + +You will need to create these yourself as part of the exercise. +This is so that you get to practice deciding on and creating the program's interface yourself, which is an important part of programming in C. +It does mean that when you first try to run the tests, they won't compile. +They will give you an error similar to: + +```bash +make: *** No rule to make target 'src/exercise_name.c', needed by 'tests.out'. Stop. +``` + +This error occurs because the `makefile` attempts to use a file that hasn't been created yet (`exercise_name.c`). +To resolve this error you will need to add a matching file to the `src` directory. +For example, for the error above you would add a file called `exercise_name.c`. + +When you try to run the tests again you will get a slightly different error. + +```bash +make: *** No rule to make target 'src/exercise_name.h', needed by 'tests.out'. Stop. +``` + +Again the `makefile` still needs another file that has yet to be created (`exercise_name.h`). +The solution to this error is similar to the last, add the matching file to the `src` directory. +For example, for the above error you would add a file called `exercise_name.h` + + +### Add the required declarations + +Running the tests a third time you see you will get new errors, similar to: + +```bash +Compiling tests.out +src/exercise_name.c:1:0: error: ISO C forbids an empty translation unit [-Werror=pedantic] +cc1: all warnings being treated as errors +test/test_exercise_name.c:13:1: error: unknown type name ‘bar_t’; did you mean ‘__bar_t’? + bar_t b = foo(a, 2.5); + ^~~~~~ + __bar_t +test/test_exercise_name.c:15:14: error: storage size of fizz isn’t known + struct baz fizz; + ^~~~ +test/test_exercise_name.c:29:20: error: implicit declaration of function ‘foo’ [-Werror=implicit-function-declaration] + bar_t b = foo_function(fizz, 2.5); +``` + +This error means that you need to add function, type and variable decarations to the header file to match those the test file is attempting to use. +In doing this you will need to look at the build errors and the test code to determine what needs to be declared in the header file. + +For example, for the error above you should declare a type named `bar_t`, a `struct` called `baz` and a function named `foo()`. +Additionally we can tell from looking at the above errors that function `foo()` has two parameters. + +The first parameter is passed an argument of `fizz` and thus should have a type of `struct baz`. +The second parameter is passed `2.5` and so could have one of two types, either `float` or `double`. +You will need to look at the test code to determine which. + +The _names_ of the parameters are not determined by the test code and so are left up to you to decide, though in keeping with C programming practices they should be descriptive but not overly long. + +Further, we can see that the the return type expected by the test code is of the type `bar_t`. + +Putting this all together we end up with a function declaration that looks like the following: + +```c +// The parameter names are not very good here they should be more descriptive in a real exercise. +// We have decide on a double for the second parameter in this hypothetical example. +bar_t foo(struct baz b, double d); +``` + +You should continue to do this for any further similar errors. +To check that you have correctly determined the required declaration, just run the tests again and analyse any errors similarly. + +Additionally, remember to add any includes to the header file any headers that it itself requires. + + +### Include guards + +Before you are finished with the header file, you should add include guards. +Include guards are used to help prevent the file from being included multiple times by accident. +If the file _was_ included multiple times then the functions and other items would be declared twice; In C this is an error because the compiler thinks you are trying to declare another _different_ function that has the same name. + +To add include guards, add something similar to the following as the first two lines of the header: + +```c +#ifndef EXERCISE_NAME_H +#define EXERCISE_NAME_H +``` + +And on the very last line: + +```c +#endif +``` + + +### Add the required definitions + +Once the header file is complete you may still have build errors similar to the following: + +```bash +Compiling tests.out +src/exercise_name.c:1:0: error: ISO C forbids an empty translation unit [-Werror=pedantic] +cc1: all warnings being treated as errors +makefile:24: recipe for target 'tests.out' failed +make: *** [tests.out] Error 1 +``` + +This is because although you have _declared_ all the items you need to, they have not yet been _defined_. +To define the needed items you need to add their implementation to the `exercise_name.c` file. +For the function `foo()` from the previous example, this would look similar to: + +```c +#include "exercise_name.h" + +bar_t foo(struct baz b, double d) +{ + // Your exercise code here +} +``` + +After having resolved these errors you should be ready to start making the tests pass! diff --git a/exercises/meetup/README.md b/exercises/meetup/README.md index d8e2310d6..37bd7867b 100644 --- a/exercises/meetup/README.md +++ b/exercises/meetup/README.md @@ -2,25 +2,155 @@ Calculate the date of meetups. -Typically meetups happen on the same day of the week. In this exercise, you will take -a description of a meetup date, and return the actual meetup date. +Typically meetups happen on the same day of the week. In this exercise, you +will take a description of a meetup date, and return the actual meetup date. Examples of general descriptions are: -- the first Monday of January 2017 -- the third Tuesday of January 2017 -- the Wednesteenth of January 2017 -- the last Thursday of January 2017 +- The first Monday of January 2017 +- The third Tuesday of January 2017 +- The wednesteenth of January 2017 +- The last Thursday of January 2017 -Note that "Monteenth", "Tuesteenth", etc are all made up words. There -was a meetup whose members realized that there are exactly 7 numbered days in a month that -end in '-teenth'. Therefore, one is guaranteed that each day of the week +The descriptors you are expected to parse are: +first, second, third, fourth, fifth, last, monteenth, tuesteenth, wednesteenth, +thursteenth, friteenth, saturteenth, sunteenth + +Note that "monteenth", "tuesteenth", etc are all made up words. There was a +meetup whose members realized that there are exactly 7 numbered days in a month +that end in '-teenth'. Therefore, one is guaranteed that each day of the week (Monday, Tuesday, ...) will have exactly one date that is named with '-teenth' in every month. -Given examples of a meetup dates, each containing a month, day, year, and descriptor -(first, second, teenth, etc), calculate the date of the actual meetup. -For example, if given "First Monday of January 2017", the correct meetup date is 2017/1/2 +Given examples of a meetup dates, each containing a month, day, year, and +descriptor calculate the date of the actual meetup. For example, if given +"The first Monday of January 2017", the correct meetup date is 2017/1/2. + +## Exercises without stub implementations + +Like the majority of C programs you will write, this exercise comes without any header file (`*.h`) or source file (`*.c`). + + +### Add the required files + +You will need to create these yourself as part of the exercise. +This is so that you get to practice deciding on and creating the program's interface yourself, which is an important part of programming in C. +It does mean that when you first try to run the tests, they won't compile. +They will give you an error similar to: + +```bash +make: *** No rule to make target 'src/exercise_name.c', needed by 'tests.out'. Stop. +``` + +This error occurs because the `makefile` attempts to use a file that hasn't been created yet (`exercise_name.c`). +To resolve this error you will need to add a matching file to the `src` directory. +For example, for the error above you would add a file called `exercise_name.c`. + +When you try to run the tests again you will get a slightly different error. + +```bash +make: *** No rule to make target 'src/exercise_name.h', needed by 'tests.out'. Stop. +``` + +Again the `makefile` still needs another file that has yet to be created (`exercise_name.h`). +The solution to this error is similar to the last, add the matching file to the `src` directory. +For example, for the above error you would add a file called `exercise_name.h` + + +### Add the required declarations + +Running the tests a third time you see you will get new errors, similar to: + +```bash +Compiling tests.out +src/exercise_name.c:1:0: error: ISO C forbids an empty translation unit [-Werror=pedantic] +cc1: all warnings being treated as errors +test/test_exercise_name.c:13:1: error: unknown type name ‘bar_t’; did you mean ‘__bar_t’? + bar_t b = foo(a, 2.5); + ^~~~~~ + __bar_t +test/test_exercise_name.c:15:14: error: storage size of fizz isn’t known + struct baz fizz; + ^~~~ +test/test_exercise_name.c:29:20: error: implicit declaration of function ‘foo’ [-Werror=implicit-function-declaration] + bar_t b = foo_function(fizz, 2.5); +``` + +This error means that you need to add function, type and variable decarations to the header file to match those the test file is attempting to use. +In doing this you will need to look at the build errors and the test code to determine what needs to be declared in the header file. + +For example, for the error above you should declare a type named `bar_t`, a `struct` called `baz` and a function named `foo()`. +Additionally we can tell from looking at the above errors that function `foo()` has two parameters. + +The first parameter is passed an argument of `fizz` and thus should have a type of `struct baz`. +The second parameter is passed `2.5` and so could have one of two types, either `float` or `double`. +You will need to look at the test code to determine which. + +The _names_ of the parameters are not determined by the test code and so are left up to you to decide, though in keeping with C programming practices they should be descriptive but not overly long. + +Further, we can see that the the return type expected by the test code is of the type `bar_t`. + +Putting this all together we end up with a function declaration that looks like the following: + +```c +// The parameter names are not very good here they should be more descriptive in a real exercise. +// We have decide on a double for the second parameter in this hypothetical example. +bar_t foo(struct baz b, double d); +``` + +You should continue to do this for any further similar errors. +To check that you have correctly determined the required declaration, just run the tests again and analyse any errors similarly. + +Additionally, remember to add any includes to the header file any headers that it itself requires. + + +### Include guards + +Before you are finished with the header file, you should add include guards. +Include guards are used to help prevent the file from being included multiple times by accident. +If the file _was_ included multiple times then the functions and other items would be declared twice; In C this is an error because the compiler thinks you are trying to declare another _different_ function that has the same name. + +To add include guards, add something similar to the following as the first two lines of the header: + +```c +#ifndef EXERCISE_NAME_H +#define EXERCISE_NAME_H +``` + +And on the very last line: + +```c +#endif +``` + + +### Add the required definitions + +Once the header file is complete you may still have build errors similar to the following: + +```bash +Compiling tests.out +src/exercise_name.c:1:0: error: ISO C forbids an empty translation unit [-Werror=pedantic] +cc1: all warnings being treated as errors +makefile:24: recipe for target 'tests.out' failed +make: *** [tests.out] Error 1 +``` + +This is because although you have _declared_ all the items you need to, they have not yet been _defined_. +To define the needed items you need to add their implementation to the `exercise_name.c` file. +For the function `foo()` from the previous example, this would look similar to: + +```c +#include "exercise_name.h" + +bar_t foo(struct baz b, double d) +{ + // Your exercise code here +} +``` + +After having resolved these errors you should be ready to start making the tests pass! + ## Getting Started diff --git a/exercises/pangram/src/example.h b/exercises/pangram/src/pangram.h similarity index 100% rename from exercises/pangram/src/example.h rename to exercises/pangram/src/pangram.h diff --git a/exercises/space-age/.meta/hints.md b/exercises/space-age/.meta/hints.md new file mode 100644 index 000000000..0197ca392 --- /dev/null +++ b/exercises/space-age/.meta/hints.md @@ -0,0 +1,124 @@ +## Exercises without stub implementations + +Like the majority of C programs you will write, this exercise comes without any header file (`*.h`) or source file (`*.c`). + + +### Add the required files + +You will need to create these yourself as part of the exercise. +This is so that you get to practice deciding on and creating the program's interface yourself, which is an important part of programming in C. +It does mean that when you first try to run the tests, they won't compile. +They will give you an error similar to: + +```bash +make: *** No rule to make target 'src/exercise_name.c', needed by 'tests.out'. Stop. +``` + +This error occurs because the `makefile` attempts to use a file that hasn't been created yet (`exercise_name.c`). +To resolve this error you will need to add a matching file to the `src` directory. +For example, for the error above you would add a file called `exercise_name.c`. + +When you try to run the tests again you will get a slightly different error. + +```bash +make: *** No rule to make target 'src/exercise_name.h', needed by 'tests.out'. Stop. +``` + +Again the `makefile` still needs another file that has yet to be created (`exercise_name.h`). +The solution to this error is similar to the last, add the matching file to the `src` directory. +For example, for the above error you would add a file called `exercise_name.h` + + +### Add the required declarations + +Running the tests a third time you see you will get new errors, similar to: + +```bash +Compiling tests.out +src/exercise_name.c:1:0: error: ISO C forbids an empty translation unit [-Werror=pedantic] +cc1: all warnings being treated as errors +test/test_exercise_name.c:13:1: error: unknown type name ‘bar_t’; did you mean ‘__bar_t’? + bar_t b = foo(a, 2.5); + ^~~~~~ + __bar_t +test/test_exercise_name.c:15:14: error: storage size of fizz isn’t known + struct baz fizz; + ^~~~ +test/test_exercise_name.c:29:20: error: implicit declaration of function ‘foo’ [-Werror=implicit-function-declaration] + bar_t b = foo_function(fizz, 2.5); +``` + +This error means that you need to add function, type and variable decarations to the header file to match those the test file is attempting to use. +In doing this you will need to look at the build errors and the test code to determine what needs to be declared in the header file. + +For example, for the error above you should declare a type named `bar_t`, a `struct` called `baz` and a function named `foo()`. +Additionally we can tell from looking at the above errors that function `foo()` has two parameters. + +The first parameter is passed an argument of `fizz` and thus should have a type of `struct baz`. +The second parameter is passed `2.5` and so could have one of two types, either `float` or `double`. +You will need to look at the test code to determine which. + +The _names_ of the parameters are not determined by the test code and so are left up to you to decide, though in keeping with C programming practices they should be descriptive but not overly long. + +Further, we can see that the the return type expected by the test code is of the type `bar_t`. + +Putting this all together we end up with a function declaration that looks like the following: + +```c +// The parameter names are not very good here they should be more descriptive in a real exercise. +// We have decide on a double for the second parameter in this hypothetical example. +bar_t foo(struct baz b, double d); +``` + +You should continue to do this for any further similar errors. +To check that you have correctly determined the required declaration, just run the tests again and analyse any errors similarly. + +Additionally, remember to add any includes to the header file any headers that it itself requires. + + +### Include guards + +Before you are finished with the header file, you should add include guards. +Include guards are used to help prevent the file from being included multiple times by accident. +If the file _was_ included multiple times then the functions and other items would be declared twice; In C this is an error because the compiler thinks you are trying to declare another _different_ function that has the same name. + +To add include guards, add something similar to the following as the first two lines of the header: + +```c +#ifndef EXERCISE_NAME_H +#define EXERCISE_NAME_H +``` + +And on the very last line: + +```c +#endif +``` + + +### Add the required definitions + +Once the header file is complete you may still have build errors similar to the following: + +```bash +Compiling tests.out +src/exercise_name.c:1:0: error: ISO C forbids an empty translation unit [-Werror=pedantic] +cc1: all warnings being treated as errors +makefile:24: recipe for target 'tests.out' failed +make: *** [tests.out] Error 1 +``` + +This is because although you have _declared_ all the items you need to, they have not yet been _defined_. +To define the needed items you need to add their implementation to the `exercise_name.c` file. +For the function `foo()` from the previous example, this would look similar to: + +```c +#include "exercise_name.h" + +bar_t foo(struct baz b, double d) +{ + // Your exercise code here +} +``` + +After having resolved these errors you should be ready to start making the tests pass! diff --git a/exercises/space-age/README.md b/exercises/space-age/README.md index 4c1c18f6b..3ebe4f215 100644 --- a/exercises/space-age/README.md +++ b/exercises/space-age/README.md @@ -12,12 +12,137 @@ Given an age in seconds, calculate how old someone would be on: - Neptune: orbital period 164.79132 Earth years So if you were told someone were 1,000,000,000 seconds old, you should -be able to say that they're 31.69 Earth-years old. Round all ages to -the nearest hundredth of a year. +be able to say that they're 31.69 Earth-years old. If you're wondering why Pluto didn't make the cut, go watch [this youtube video](http://www.youtube.com/watch?v=Z_2gbGXzFbs). +## Exercises without stub implementations + +Like the majority of C programs you will write, this exercise comes without any header file (`*.h`) or source file (`*.c`). + + +### Add the required files + +You will need to create these yourself as part of the exercise. +This is so that you get to practice deciding on and creating the program's interface yourself, which is an important part of programming in C. +It does mean that when you first try to run the tests, they won't compile. +They will give you an error similar to: + +```bash +make: *** No rule to make target 'src/exercise_name.c', needed by 'tests.out'. Stop. +``` + +This error occurs because the `makefile` attempts to use a file that hasn't been created yet (`exercise_name.c`). +To resolve this error you will need to add a matching file to the `src` directory. +For example, for the error above you would add a file called `exercise_name.c`. + +When you try to run the tests again you will get a slightly different error. + +```bash +make: *** No rule to make target 'src/exercise_name.h', needed by 'tests.out'. Stop. +``` + +Again the `makefile` still needs another file that has yet to be created (`exercise_name.h`). +The solution to this error is similar to the last, add the matching file to the `src` directory. +For example, for the above error you would add a file called `exercise_name.h` + + +### Add the required declarations + +Running the tests a third time you see you will get new errors, similar to: + +```bash +Compiling tests.out +src/exercise_name.c:1:0: error: ISO C forbids an empty translation unit [-Werror=pedantic] +cc1: all warnings being treated as errors +test/test_exercise_name.c:13:1: error: unknown type name ‘bar_t’; did you mean ‘__bar_t’? + bar_t b = foo(a, 2.5); + ^~~~~~ + __bar_t +test/test_exercise_name.c:15:14: error: storage size of fizz isn’t known + struct baz fizz; + ^~~~ +test/test_exercise_name.c:29:20: error: implicit declaration of function ‘foo’ [-Werror=implicit-function-declaration] + bar_t b = foo_function(fizz, 2.5); +``` + +This error means that you need to add function, type and variable decarations to the header file to match those the test file is attempting to use. +In doing this you will need to look at the build errors and the test code to determine what needs to be declared in the header file. + +For example, for the error above you should declare a type named `bar_t`, a `struct` called `baz` and a function named `foo()`. +Additionally we can tell from looking at the above errors that function `foo()` has two parameters. + +The first parameter is passed an argument of `fizz` and thus should have a type of `struct baz`. +The second parameter is passed `2.5` and so could have one of two types, either `float` or `double`. +You will need to look at the test code to determine which. + +The _names_ of the parameters are not determined by the test code and so are left up to you to decide, though in keeping with C programming practices they should be descriptive but not overly long. + +Further, we can see that the the return type expected by the test code is of the type `bar_t`. + +Putting this all together we end up with a function declaration that looks like the following: + +```c +// The parameter names are not very good here they should be more descriptive in a real exercise. +// We have decide on a double for the second parameter in this hypothetical example. +bar_t foo(struct baz b, double d); +``` + +You should continue to do this for any further similar errors. +To check that you have correctly determined the required declaration, just run the tests again and analyse any errors similarly. + +Additionally, remember to add any includes to the header file any headers that it itself requires. + + +### Include guards + +Before you are finished with the header file, you should add include guards. +Include guards are used to help prevent the file from being included multiple times by accident. +If the file _was_ included multiple times then the functions and other items would be declared twice; In C this is an error because the compiler thinks you are trying to declare another _different_ function that has the same name. + +To add include guards, add something similar to the following as the first two lines of the header: + +```c +#ifndef EXERCISE_NAME_H +#define EXERCISE_NAME_H +``` + +And on the very last line: + +```c +#endif +``` + + +### Add the required definitions + +Once the header file is complete you may still have build errors similar to the following: + +```bash +Compiling tests.out +src/exercise_name.c:1:0: error: ISO C forbids an empty translation unit [-Werror=pedantic] +cc1: all warnings being treated as errors +makefile:24: recipe for target 'tests.out' failed +make: *** [tests.out] Error 1 +``` + +This is because although you have _declared_ all the items you need to, they have not yet been _defined_. +To define the needed items you need to add their implementation to the `exercise_name.c` file. +For the function `foo()` from the previous example, this would look similar to: + +```c +#include "exercise_name.h" + +bar_t foo(struct baz b, double d) +{ + // Your exercise code here +} +``` + +After having resolved these errors you should be ready to start making the tests pass! + + ## Getting Started Make sure you have read the