Instructions
- Only this page will serve as reference.
- Make sure you have the appropriate permissions on your files and directories.
- You have to follow the submission procedures for all your exercises.
- Your exercises will be checked and graded by your fellow classmates.
- On top of that, your exercises will be checked and graded by a program called Moulinette.
- Moulinette is very meticulous and strict in its evaluation of your work. It is entirely automated and there is no way to negotiate with it. So if you want to avoid bad surprises, be as thorough as possible.
- Moulinette is not very open-minded. It won’t try and understand your code if it doesn’t respect the Norm. Moulinette relies on a program called norminette to check if your files respect the norm. TL;DR: it would be idiotic to submit a piece of work that doesn’t pass norminette’s check.
- Using an external function that is not explicitly allowed by the subject will get you a 0.
- You’ll only have to submit a main() function if we ask for a program.
- Moulinette compiles with these flags:
-Wall -Wextra -Werror, and usescc. - If your program doesn’t compile, you’ll get 0.
- We expect your repository to be clean. This means you can only hand in the files asked by the subject, and useful files like
.gitignoreandREADME.md - Got a question? Ask your peer on the right. Otherwise, try your peer on the left.
Advice: Do not forget to add the standard 42 header in each of your .c/.h files. The norminette check its existence anyway!
Warning: Norminette must be launched with the -R CheckForbiddenSourceHeader flag. Moulinette will use it too.
my_add
| my_add | |
|---|---|
| Turn-in directory | 00_my_add/ |
| Files to turn in | my_add.c |
| Allowed external functions | None |
| Type of work | Function |
- Write a program which displays the character
con standard output. - To help you get started, we will provide some code for you to copy/paste/edit. Make sure you understand every line before you hand it in!
- You need to write a function that takes two integers as parameters and returns the result of the addition of the two integers.
#include <stdio.h> int my_add(int a, int b) { //Your code } // WHEN YOU ARE ASKED FOR A FUNCTION // WE WILL USE OUR OWN MAIN FUNCTION WITH MORE TEST // TO TEST YOUR EXERCISE // SO YOU NEED TO REMOVE YOUR MAIN FUNCTION // OR COMMENT IT OUT //This main is very limited you test your code with more complex inputs and outputs to make sure your function cover all the cases. int main() { int a = 1; int b = 2; int result = my_add(a, b); //The function printf allows you to print integers and strings to the console easily it's very handy for debugging purposes make sure to always remove it before you submit your work. printf("%d\n", result); return 0; }
Example output:
$ ./a.out
3$
my_operation
| my_operation | |
|---|---|
| Turn-in directory | 01_my_operation/ |
| Files to turn in | my_operation.c |
| Allowed external functions | None |
| Type of work | Function |
- Write a program which displays the character
con standard output, followed by a newline. - To help you get started, we will provide some code for you to copy/paste/edit. Make sure you understand every line before you hand it in!
- You need to write a function that takes two integers as parameters and returns the result of the operation specified by the third parameter.
- The third parameter is a character that can be one of the following: '+', '-', '*', '/' or '%'.
- If the operation is illegal, the function returns 0.
- If the third parameter is not one of the above, the function returns 0.
#include <stdio.h> int my_operation(int a, int b, char operation) { if (operation == '+') return a + b; return 0; } // LAST WARNING // WHEN YOU ARE ASKED FOR A FUNCTION // WE WILL USE OUR OWN MAIN FUNCTION TO TEST YOUR EXERCISE // SO YOU NEED TO REMOVE THE MAIN FUNCTION // OR COMMENT IT OUT int main() { char c = '+'; int a = 1; int b = 2; int result = my_operation(a, b, c); printf("%d\n", result); return 0; }
Example output:
$ ./a.out
3$
convert_to_ascii
| convert_to_ascii | |
|---|---|
| Turn-in directory | 02_convert_to_ascii/ |
| Files to turn in | convert_to_ascii.c |
| Allowed functions | None |
| Type of work | Function |
- Write a program which displays
Hello Codam!on standard output, followed by a newline. - To help you get started, we will provide some code for you to copy/paste/edit. Make sure you understand every line before you hand it in!
- You need to write a function that takes an integer as a parameter and returns the character that represent it if the integer is between 0 and 9. Otherwise, the function returns '\0'.
- You need to fix the prototype of the function in the provided code to have the proper return type and parameter type before implementing the function.
#include <stdio.h> return_type convert_to_ascii(parameter_type parameter_name); int main() { int five = 5; char c = convert_to_ascii(five); putchar(c); if (c == '5') printf("The function seems to work!"); else printf("The function doesn't work!"); return 0; }
Example output:
$ ./a.out
"The function seems to work!$
array_sum
| array_sum | |
|---|---|
| Turn-in directory | 03_array_sum/ |
| Files to turn in | array_sum.c |
| Allowed external functions | None |
| Type of work | Function |
- Write a program which displays the lowercase alphabet on standard output, followed by a newline.
- To help you get started, we will provide some code for you to copy/paste/edit. Make sure you understand every line before you hand it in!
- You need to write a function that takes an array of 15 integers as a parameter and returns the sum of all the elements in the array.
#include <stdio.h> int array_sum(int array[15]); int main() { int array[15] = {3,23,-3,14,7,66,71,8,9,10,131,2,1,1,5}; int result = array_sum(array); printf("%d\n", result); return (0); }
Example output:
$ ./a.out
120$
array_average
| array_average | |
|---|---|
| Turn-in directory | 04_array_average/ |
| Files to turn in | array_average.c |
| Allowed external functions | None |
| Type of work | Function |
- Write a program which displays the alphabet in lowercase on standard output, starting from the character in variable
start_char, followed by a newline. - To help you get started, we will provide some code for you to copy/paste/edit. Make sure you understand every line before you hand it in!
- You need to write a function that takes an array of integers and its length as parameters and returns the average of the integers in the array.
- If the array is empty (len == 0), the function should return 0.
#include <stdio.h> int array_average(const int *a, const size_t len); int main() { int array[3] = {3, 22, 5}; size_t len = 3; int result = array_average(array, len); printf("%d\n", result); return 0; }
Example output:
$ ./a.out
10$
string_length
| string_length | |
|---|---|
| Turn-in directory | 05_string_length/ |
| Files to turn in | string_length.c |
| Allowed external functions | None |
| Type of work | Function |
- Write a program which displays the alphabet in lowercase on standard output, starting from the character in variable
start_char, ending with the character instop_char, followed by a newline. - To help you get started, we will provide some code for you to copy/paste/edit. Make sure you understand every line before you hand it in!
- You need to write a function that takes a C string as a parameter and returns the length of the string.
#include <stdio.h> size_t string_length(const char* str); int main() { const char *hello = "Hello"; size_t result = string_length(hello); printf("%d\n", result); return 0; }
Example output:
$ ./a.out
5$
string_print
| string_print | |
|---|---|
| Turn-in directory | 06_string_print/ |
| Files to turn in | string_print.c |
| Allowed external functions | putchar |
| Type of work | Function |
- Write a program which displays the alphabet in alternating lower and uppercase on standard output, starting from the character in variable
start_char, followed by a newline. - To help you get started, we will provide some code for you to copy/paste/edit. Make sure you understand every line before you hand it in!
- You need to write a function that takes a C string as a parameter and prints it to the standard output.
#include <stdio.h> void string_print(const char* str); int main() { const char *hello = "Hello\n"; string_print(hello); return 0; }
Example output:
$ ./a.out
Hello$
string_is_number
| string_is_number | |
|---|---|
| Turn-in directory | 07_string_is_number/ |
| Files to turn in | string_is_number.c |
| Allowed external functions | None |
| Type of work | Function |
- Write a program which displays the alphabet based on the starting character in variable
start_char, followed by a newline. Use the following rules: - To help you get started, we will provide some code for you to copy/paste/edit. Make sure you understand every line before you hand it in! #TODO SUBJECT HERE
#include <stdio.h> int string_is_number(const char* str); int main() { const char *hello = "Hello"; const char *number = "123"; int result = string_is_number(hello); printf("%d\n", result); result = string_is_number(number); printf("%d\n", result); return 0; }
Example output:
$ ./a.out
0$
1$
string_copy
| string_copy | |
|---|---|
| Turn-in directory | 08_string_copy/ |
| Files to turn in | string_copy.c |
| Allowed external functions | None |
| Type of work | Function |
- Write a program which displays the alphabet based on the starting character in variable
start_char, followed by a newline. Use the following rules: - To help you get started, we will provide some code for you to copy/paste/edit. Make sure you understand every line before you hand it in!
- You need to write a function that takes an array of integers and its length as parameters and returns the average of the integers in the array.
#include <stdio.h> void string_copy(char* destination, const char* source); int main() { const char *hello = "Hello"; char a[10]; string_copy(a, hello); string_print(a); return 0; }
Example output:
$ ./a.out
Hello$
Submission & Evaluation
Turn in your assignment in your Git repository. Only the work on the main branch of your repository will be evaluated during the defense. Don’t hesitate to double check the names of your files to ensure they are correct.
Warning You need to add only the files requested by the subject. Usefull files like
.gitignoreandREADME.mdare also allowed, garbage like.DS_Storeor*.ofiles will turn your grade into a 0.