diff --git a/Recap Island.html b/Recap Island.html new file mode 100644 index 0000000..56fff6f --- /dev/null +++ b/Recap Island.html @@ -0,0 +1,2015 @@ + + +
1.0.2 2026-02-23 10:42 2026-03-02 10:42 submit-* (limit: 3 per week) archi-* (limit: 2 per hour) epita-prepa-computer-science-prog-103-p-06-2030-firstname.lastname
+├── recap_island
+│ ├── fundamentals
+│ │ ├── Makefile
+│ │ ├── main.c
+│ │ ├── quotes.c
+│ │ ├── village.h
+│ │ ├── village_manager.c
+│ │ └── villagers.c
+│ └── proficiencies
+│ ├── strange_list.c
+│ └── strange_list.h
+├── .gitignore
+└── README
+firstname.lastname with your login. .gitignore file is mandatory. Tests folder. .gitignore file:*.a
+*.lib
+*.o
+*.obj
+*.out
+
+.idea/
+*~
+*.DotSettings.user
+<stdlib.h> and <stddef.h> libraries, unless clearly specified.Given Files. This is an archive file. To use it, you need to untar it using the following command:tar -xvf assets.tar.gz
+ fundamentals/village.h enum works which contains the following four activities:WORKERSELLERMUSICIANUNEMPLOYEDstruct villager which will hold the following attributes for every villager:char *name that will hold the name of the villagerunsigned int age to keep track of its ageenum works job to know which activity it doeschar *favorite_quote to keep its favorite quote in mindfundamentals/quotes.c name.village is an array of struct villager.population is the length of the array.name is the name of the villager whose quote you will return.village is NULL or population equals 0, you will return NULL.char *get_quote(const struct villager *village, unsigned int population, char *name);
+ #include <stdio.h>
+
+int main(void)
+{
+ struct villager village[2] = {
+ {
+ .name = "Tom Nook",
+ .age = 99,
+ .job = SELLER,
+ .favorite_quote = "It's 42 bells",
+ },
+ {
+ .name = "Marie",
+ .age = 23,
+ .job = WORKER,
+ .favorite_quote = "It's so expensive!",
+ },
+ };
+ unsigned int population = 2;
+
+ char *quote = get_quote(village, population, "Tom Nook");
+ printf("- %s\n", quote);
+
+ quote = get_quote(village, population, "Marie");
+ printf("- %s\n", quote);
+
+ quote = get_quote(village, population, "TC");
+ printf("%p\n", quote);
+}
+ - It's 42 bells
+- It's so expensive!
+(nil)
+ village inside the file named filename, with a newline after each quote.filename is the file you will write to.village is an array of struct villager.population is the length of the array.village or the filename is NULL.stdio.h library.int list_quotes(const char *filename, const struct villager *village, unsigned int population);
+ #include <stdio.h>
+
+int main(void)
+{
+ struct villager village[2] = {
+ {
+ .name = "Tom Nook",
+ .age = 99,
+ .job = SELLER,
+ .favorite_quote = "It's 42 bells",
+ },
+ {
+ .name = "Marie",
+ .age = 23,
+ .job = WORKER,
+ .favorite_quote = "It's so expensive!",
+ },
+ };
+ unsigned int population = 2;
+
+ int err = list_quotes("/tmp/list_quotes", village, population);
+ printf("%d\n", err);
+
+ err = list_quotes(NULL, village, population);
+ printf("%d\n", err);
+}
+ 0
+-1
+$ cat /tmp/list_quotes
+It's 42 bells
+It's so expensive!
+ filename.filename is the file you will read.filename is NULL, if an error occurs while opening or reading the file or the file only has one line, you should return NULL.stdio.h library.char *second_longest_quote(const char *filename);
+ #include <stdio.h>
+#include <stdlib.h>
+
+int main(void)
+{
+ // $ cat /tmp/list_quotes
+ // It's 42 bells
+ // It's so expensive!
+ char *quote = second_longest_quote("/tmp/list_quotes");
+ printf("%s\n", quote);
+ free(quote);
+
+ quote = second_longest_quote("/");
+ printf("%p\n", quote);
+
+ free(quote);
+}
+ It's 42 bells
+(nil)
+ fundamentals/villagers.c village is an array of struct villager.population is the length of the array.village is NULL or population equals 0, you will return NULL.char *oldest_villager(const struct villager *village, unsigned int population);
+ #include <stdio.h>
+
+int main(void)
+{
+ struct villager village[2] = {
+ {
+ .name = "Tom Nook",
+ .age = 99,
+ .job = SELLER,
+ .favorite_quote = "It's 42 bells",
+ },
+ {
+ .name = "Marie",
+ .age = 23,
+ .job = WORKER,
+ .favorite_quote = "It's so expensive!",
+ },
+ };
+ unsigned int population = 2;
+
+ char *oldest = oldest_villager(village, population);
+ printf("Hi %s!\n", oldest);
+
+ oldest = oldest_villager(NULL, 0);
+ printf("%p\n", oldest);
+}
+ Hi Tom Nook!
+(nil)
+ village is an array of struct villager.population is the length of the array.village is NULL or if the population equals 0, you will return -1.float average_village_age(const struct villager *village, unsigned int population);
+ #include <stdio.h>
+
+int main(void)
+{
+ struct villager village[2] = {
+ {
+ .name = "Tom Nook",
+ .age = 99,
+ .job = SELLER,
+ .favorite_quote = "It's 42 bells",
+ },
+ {
+ .name = "Marie",
+ .age = 23,
+ .job = WORKER,
+ .favorite_quote = "It's so expensive!",
+ },
+ };
+ unsigned int population = 2;
+
+ float avg = average_village_age(village, population);
+ printf("Avg: %.2f\n", avg);
+
+ avg = average_village_age(village, 0);
+ printf("Avg: %.2f\n", avg);
+}
+ Avg: 61.00
+Avg: -1.00
+ enum works.village is an array of struct villager.population is the length of the array.village is NULL, you will not do anything.void sort_village(struct villager *village, unsigned int population);
+ #include <stdio.h>
+
+int main(void)
+{
+ struct villager village[2] = {
+ {
+ .name = "Tom Nook",
+ .age = 99,
+ .job = SELLER,
+ .favorite_quote = "It's 42 bells",
+ },
+ {
+ .name = "Marie",
+ .age = 23,
+ .job = WORKER,
+ .favorite_quote = "It's so expensive!",
+ },
+ };
+ unsigned int population = 2;
+
+ sort_village(village, population);
+
+ for (unsigned int i = 0; i < population; i++)
+ {
+ printf("I'm %s (%d)\n", village[i].name, village[i].age);
+ }
+}
+ I'm Marie (23)
+I'm Tom Nook (99)
+ fundamentals/village_manager.c village is a pointer to an array of struct villager.population is a pointer to the length of the array.villager is the new element to be added at the end of village.village to add villager.village or the population is NULL.population!int add_villager(struct villager **village, unsigned int *population, struct villager villager);
+ #include <stdio.h>
+#include <stdlib.h>
+
+int main(void)
+{
+ struct villager *village = NULL;
+ unsigned int population = 0;
+
+ struct villager tom_nook = {
+ .name = "Tom Nook",
+ .age = 99,
+ .job = SELLER,
+ .favorite_quote = "It's 42 bells",
+ };
+
+ int err = add_villager(&village, &population, tom_nook);
+ printf("%d\n", err);
+
+ struct villager marie = {
+ .name = "Marie",
+ .age = 23,
+ .job = WORKER,
+ .favorite_quote = "It's so expensive!",
+ };
+
+ err = add_villager(&village, &population, marie);
+ printf("%d\n", err);
+
+ err = add_villager(&village, NULL, marie);
+ printf("%d\n", err);
+
+ for (unsigned int i = 0; i < population; i++)
+ {
+ printf("I'm %s (%d)\n", village[i].name, village[i].age);
+ }
+
+ free(village);
+}
+ 0
+0
+-1
+I'm Tom Nook (99)
+I'm Marie (23)
+ village is a pointer to an array of struct villager.population is a pointer to the length of the array.name is the name of the villager to be removed from village.village or the population is NULL, or no corresponding villager is found.name is found, you must move all the villagers following it by one space to the left.population!int remove_villager(struct villager **village, unsigned int *population, char *name);
+ strcmp function from the string.h header.#include <stdio.h>
+#include <stdlib.h>
+
+int main(void)
+{
+ struct villager *village = NULL;
+ unsigned int population = 0;
+
+ struct villager tom_nook = {
+ .name = "Tom Nook",
+ .age = 99,
+ .job = SELLER,
+ .favorite_quote = "It's 42 bells",
+ };
+
+ add_villager(&village, &population, tom_nook);
+
+ struct villager marie = {
+ .name = "Marie",
+ .age = 23,
+ .job = WORKER,
+ .favorite_quote = "It's so expensive!",
+ };
+
+ add_villager(&village, &population, marie);
+
+ int err = remove_villager(&village, &population, "Tom Nook");
+ printf("%d\n", err);
+
+ err = remove_villager(&village, &population, "Tom Nook");
+ printf("%d\n", err);
+
+ err = remove_villager(NULL, &population, "Marie");
+ printf("%d\n", err);
+
+ for (unsigned int i = 0; i < population; i++)
+ {
+ printf("I'm %s (%d)\n", village[i].name, village[i].age);
+ }
+
+ free(village);
+}
+ 0
+-1
+-1
+I'm Marie (23)
+ village is a pointer to an array of struct villager.population is a pointer to the length of the array.village or the population is NULL.population and set the content of village to NULL.void clear_village(struct villager **village, unsigned int *population);
+ #include <stdio.h>
+
+int main(void)
+{
+ struct villager *village = NULL;
+ unsigned int population = 0;
+
+ struct villager tom_nook = {
+ .name = "Tom Nook",
+ .age = 99,
+ .job = SELLER,
+ .favorite_quote = "It's 42 bells",
+ };
+
+ add_villager(&village, &population, tom_nook);
+
+ struct villager marie = {
+ .name = "Marie",
+ .age = 23,
+ .job = WORKER,
+ .favorite_quote = "It's so expensive!",
+ };
+
+ add_villager(&village, &population, marie);
+
+ clear_village(&village, &population);
+
+ for (unsigned int i = 0; i < population; i++)
+ {
+ printf("I'm %s (%d)\n", village[i].name, village[i].age);
+ }
+
+ printf("%p\n", village);
+ printf("%u\n", population);
+}
+ (nil)
+0
+ fundamentals/Makefile main.c file to test your code.all, compiling your files and the main.c, as well as a clean that removes everything your makefile generated.-Wall -Wextra -Werrorproficiencies/strange_list.h enum data_type, containing the following elements: union value containing the float f, the int i and the char *s.struct data containing the enum data_type type and the union value value.proficiencies/strange_list.c list. If list is NULL, you will do nothing.void print_strange_list(const struct data *list, unsigned int size);
+ INT : {i}
+FLOAT : {f}
+STRING : {s}
+ stdio.h header for the printf function, and the string.h header in case you would like to use a padding function. strange_list.c you are not allowed to use any of their functions anywhere else in this file, except if you are told otherwise.list.list to append element at the end. Be careful, you will need to update the size! list or size is NULLint append_strange_list(struct data **list, unsigned int *size, struct data element);
+ #include <stdio.h>
+#include <stdlib.h>
+
+int main(void)
+{
+ struct data *list = NULL;
+ unsigned int size = 0;
+
+ struct data elt1 = { .type = INT_TYPE, .value = { .i = 42 } };
+ struct data elt2 = { .type = STRING_TYPE, .value = { .s = "QUOI" } };
+
+ int err = append_strange_list(&list, &size, elt1);
+ printf("%d\n", err);
+
+ err = append_strange_list(&list, &size, elt2);
+ printf("%d\n", err);
+
+ err = append_strange_list(&list, NULL, elt1);
+ printf("%d\n", err);
+
+ print_strange_list(list, size);
+
+ free(list);
+}
+ 0
+0
+-1
+INT : 42
+STRING : QUOI
+ index of the list. You will then need to resize list to the right size and update size.list is NULL or size is NULL or if index is out of range.int remove_at_strange_list(struct data **list, unsigned int *size, int index);
+ #include <stdio.h>
+#include <stdlib.h>
+
+int main(void)
+{
+ struct data *list = NULL;
+ unsigned int size = 0;
+
+ struct data elt1 = { .type = INT_TYPE, .value = { .i = 42 } };
+ struct data elt2 = { .type = STRING_TYPE, .value = { .s = "FEUR" } };
+
+ append_strange_list(&list, &size, elt1);
+ append_strange_list(&list, &size, elt2);
+ append_strange_list(&list, &size, elt2);
+
+ int err = remove_at_strange_list(&list, &size, 1);
+ printf("%d\n", err);
+
+ err = remove_at_strange_list(&list, &size, 42);
+ printf("%d\n", err);
+
+ print_strange_list(list, size);
+
+ free(list);
+}
+ 0
+-1
+INT : 42
+STRING : FEUR
+ print_strange_list, but inside of a file. If the file already contain something, you should override it.filename or list is NULL.int list_strange_list(const char *filename, const struct data *list, unsigned int size);
+ #include <stdio.h>
+#include <stdlib.h>
+
+int main(void)
+{
+ struct data *list = NULL;
+ unsigned int size = 0;
+
+ struct data elt1 = { .type = INT_TYPE, .value = { .i = 42 } };
+ struct data elt2 = { .type = STRING_TYPE, .value = { .s = "welcome2u" } };
+
+ append_strange_list(&list, &size, elt1);
+
+ append_strange_list(&list, &size, elt2);
+
+ int err = list_strange_list("/tmp/list", list, size);
+ printf("%d\n", err);
+
+ err = list_strange_list("/", list, size);
+ printf("%d\n", err);
+
+ free(list);
+}
+ 0
+-2
+$ cat /tmp/list
+INT : 42
+STRING : welcome2u
+ 1.0.2 ] 2026-02-23 21:00:00 villager.c > oldest_villager: village instead of villager strange_list.c > given_mains: wrong type for size 1.0.1 ] 2026-02-23 16:00:00 quotes.c > second_longest_quote: mention of name instead of filename