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 uses cc.
  • 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 .gitignore and README.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.

print_first_digit
Turn-in directory00_print_first_digit/
Files to turn inprint_first_digit.c
Allowed functionsputchar
include <stdio.h>

void print_first_digit(unsigned int num);

int main()
{
    print_first_digit(39);
    return 0;
}

Example output:

$ ./a.out
9$
print_any_digit
Turn-in directory01_print_any_digit/
Files to turn inprint_any_digit.c
Allowed functionsputchar
  • Write a function which prints only the digit in the position specified by position of the unsigned integer num represented in the decimal numeral system.
  • The first position is represented by the value 0. Since the decimal numeral system has infinite positions, all positions always have a value! Even when you normally wouldn't print/write that value.
include <stdio.h>

void print_any_digit(unsigned int num, unsigned int position);

int main()
{
    print_any_digit(2839, 2);
    return 0;
}

Example output:

$ ./a.out
8$
print_digits
Turn-in directory02_print_digits/
Files to turn inprint_digits.c
Allowed functionsputchar
  • Write a function which prints the value of the unsigned integer num represented in the decimal numeral system. It has to be able to print all possible values.
  • You are not allowed to use recursion. If you don't know what recursion is, don't worry, you'll learn it later.
include <stdio.h>

void print_digits(unsigned int num);

int main()
{
    print_digits(28390);
    return 0;
}

Example output:

$ ./a.out
28390$
print_number
Turn-in directory03_print_number/
Files to turn inprint_number.c
Allowed functionsputchar
  • Write a function which prints the value of the integer num represented in the decimal numeral system. It has to be able to print all possible values.
  • You are not allowed to use recursion. If you don't know what recursion is, don't worry, you'll learn it later.
  • This is a good moment to learn more about C data types
include <stdio.h>

void print_number(int num);

int main()
{
    print_number(-28390);
    return 0;
}

Example output:

$ ./a.out
-28390$

parse_string_to_int

parse_string_to_int
Turn-in directory05_parse_string_to_int/
Files to turn inparse_string_to_int.c
Allowed functionsnone
  • Write a function which parses a string str into an integer, and returns the value.
  • The string should contain a valid decimal integer. If it doesn't, your function should return 0.
  • The string can start with 1 '-' character, in which case your function should return a negative number.
  • If you encounter any character that is not a digit, or a '-' at the start, your function should return 0.
  • Don't worry about the number in the string being to large to fit inside an integer. We will consider this undefined behaviour, meaning your code can do whatever you want in this case, as long as it doesn't crash.
include <stdio.h>

int parse_string_to_int(char* str);

int main(int argc, char **argv)
{
    if (argc < 2) {
        return 1;
    }
    char *str_from_parameters = argv[1];
    int num = parse_string_to_int(str_from_parameters);
    printf("%d\n", num);
    return 0;
}

Example output:

$ ./a.out "-5000"
-5000
$ ./a.out "0039"
39
$ ./a.out "--45"
0
$ ./a.out "764.34"
0

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 .gitignore and README.md are also allowed, garbage like .DS_Store or *.o files will turn your grade into a 0.