jaunes
This commit is contained in:
14
HolidayTrip/Fundamentals/my_strings/Makefile
Normal file
14
HolidayTrip/Fundamentals/my_strings/Makefile
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
CC=gcc
|
||||||
|
SRC = my_strings.c main.c
|
||||||
|
CFLAGS= -Wall -Wextra -Werror
|
||||||
|
LDFLAGS= -fsanitize=address -g
|
||||||
|
# Computes the basic main for tests
|
||||||
|
main: ${SRC}
|
||||||
|
gcc $(CFLAGS) $^ -o main -lm
|
||||||
|
|
||||||
|
#Check for memory errors/leaks and to use gdb
|
||||||
|
debug: ${SRC}
|
||||||
|
gcc $(CFLAGS) $^ -o debug $(LDFLAGS)
|
||||||
|
|
||||||
|
clean:
|
||||||
|
$(RM) main debug
|
||||||
24
HolidayTrip/Fundamentals/my_strings/main.c
Normal file
24
HolidayTrip/Fundamentals/my_strings/main.c
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#include "my_strings.h"
|
||||||
|
|
||||||
|
int main(){
|
||||||
|
|
||||||
|
|
||||||
|
// struct string *str = my_str_init("Hello World!", 12);
|
||||||
|
// printf("data: %.*s\n", (int)str->size, str->data);
|
||||||
|
|
||||||
|
|
||||||
|
//struct string *str = my_str_init("Hello World!", 12);
|
||||||
|
//my_str_destroy(str);
|
||||||
|
|
||||||
|
//struct string *str = my_str_init("Hello Alien World!", 18);
|
||||||
|
//my_str_puts(str);
|
||||||
|
// my_str_destroy(str);
|
||||||
|
|
||||||
|
struct string *str = my_str_init("Hello ", 6);
|
||||||
|
str = my_str_n_cat(str, "Alien World!", 13);
|
||||||
|
my_str_puts(str);
|
||||||
|
my_str_destroy(str);
|
||||||
|
|
||||||
|
}
|
||||||
66
HolidayTrip/Fundamentals/my_strings/my_strings.c
Normal file
66
HolidayTrip/Fundamentals/my_strings/my_strings.c
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
#include "my_strings.h"
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
//' -> ' est un racc pour *rslt.data
|
||||||
|
struct string *my_str_init(const char* s, size_t size){
|
||||||
|
|
||||||
|
struct string *rslt = malloc(sizeof(struct string));
|
||||||
|
if(rslt == NULL) return NULL;
|
||||||
|
|
||||||
|
if(size == 0 || s == NULL) {
|
||||||
|
rslt->data = NULL;
|
||||||
|
rslt->size = 0;
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
rslt->data = malloc(size);
|
||||||
|
if(rslt->data == NULL){
|
||||||
|
free(rslt);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
memcpy(rslt->data, s, size);
|
||||||
|
rslt->size = size;
|
||||||
|
}
|
||||||
|
return rslt;
|
||||||
|
}
|
||||||
|
|
||||||
|
void my_str_destroy(struct string *str){
|
||||||
|
|
||||||
|
if(str == NULL) return;
|
||||||
|
|
||||||
|
free(str->data);
|
||||||
|
free(str);
|
||||||
|
}
|
||||||
|
|
||||||
|
void my_str_puts(struct string *str){
|
||||||
|
|
||||||
|
if(str == NULL) return;
|
||||||
|
|
||||||
|
|
||||||
|
if(str->data == NULL || str->size == 0)printf("\n");
|
||||||
|
|
||||||
|
for (size_t i = 0; i < str->size; i++) putchar(*((str->data) + i));
|
||||||
|
}
|
||||||
|
|
||||||
|
struct string *my_str_n_cat(struct string *str1, const char *str2, size_t str2_len){
|
||||||
|
|
||||||
|
if (str2 == NULL || str2_len == 0) return str1;
|
||||||
|
|
||||||
|
if (str1 == NULL){
|
||||||
|
struct string *rslt = my_str_init(str2, str2_len);
|
||||||
|
return rslt;
|
||||||
|
}
|
||||||
|
|
||||||
|
str1->data = realloc(str1->data, (str1->size + str2_len) * sizeof(char));
|
||||||
|
if(str1 == NULL) return str1;
|
||||||
|
|
||||||
|
//printf("test");
|
||||||
|
int index = 0;
|
||||||
|
while (*(str2 + index)){
|
||||||
|
str1->data[str1->size + index] = str2[index];
|
||||||
|
index ++;
|
||||||
|
}
|
||||||
|
str1->size = str1->size + index;
|
||||||
|
return str1;
|
||||||
|
}
|
||||||
17
HolidayTrip/Fundamentals/my_strings/my_strings.h
Normal file
17
HolidayTrip/Fundamentals/my_strings/my_strings.h
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
#ifndef MY_STRINGS_H
|
||||||
|
#define MY_STRINGS_H
|
||||||
|
#include <strings.h>
|
||||||
|
|
||||||
|
struct string{
|
||||||
|
char *data;
|
||||||
|
size_t size;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct string *my_str_init(const char* s, size_t size);
|
||||||
|
|
||||||
|
void my_str_destroy(struct string *str);
|
||||||
|
void my_str_puts(struct string *str);
|
||||||
|
struct string *my_str_n_cat(struct string *str1, const char *str2, size_t str2_len);
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
||||||
15
HolidayTrip/Fundamentals/radar/Makefile
Normal file
15
HolidayTrip/Fundamentals/radar/Makefile
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
CC=gcc
|
||||||
|
SRC = radar.c main.c
|
||||||
|
CFLAGS= -Wall -Wextra -Werror
|
||||||
|
LDFLAGS= -fsanitize=address -g -lm
|
||||||
|
|
||||||
|
# Computes the basic main for tests
|
||||||
|
main: ${SRC}
|
||||||
|
gcc $(CFLAGS) $^ -o main -lm
|
||||||
|
|
||||||
|
#Check for memory errors/leaks and to use gdb
|
||||||
|
debug: ${SRC}
|
||||||
|
gcc $(CFLAGS) $^ -o debug $(LDFLAGS)
|
||||||
|
|
||||||
|
clean:
|
||||||
|
$(RM) main debug
|
||||||
BIN
HolidayTrip/Fundamentals/radar/main
Executable file
BIN
HolidayTrip/Fundamentals/radar/main
Executable file
Binary file not shown.
43
HolidayTrip/Fundamentals/radar/main.c
Normal file
43
HolidayTrip/Fundamentals/radar/main.c
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#include "radar.h"
|
||||||
|
|
||||||
|
int main(){
|
||||||
|
// compute_distance
|
||||||
|
struct point p1 = { 0.0, 0.0 };
|
||||||
|
struct point p2 = { 3.0, 4.0 };
|
||||||
|
|
||||||
|
double dist = compute_distance(p1, p2);
|
||||||
|
printf("Distance: %.2f\n", dist);
|
||||||
|
|
||||||
|
// is_in_area
|
||||||
|
struct point center = { 5.0, 5.0 };
|
||||||
|
double radius = 3.0;
|
||||||
|
|
||||||
|
struct point inside_point = { 7.0, 7.0 };
|
||||||
|
struct point outside_point = { 9.0, 9.0 };
|
||||||
|
|
||||||
|
int inside = is_in_area(center, radius, inside_point);
|
||||||
|
int outside = is_in_area(center, radius, outside_point);
|
||||||
|
|
||||||
|
printf("Inside: %d\n", inside);
|
||||||
|
printf("Outside: %d\n", outside);
|
||||||
|
|
||||||
|
// detect_points
|
||||||
|
center.x = 10.0;
|
||||||
|
center.y = 10.0;
|
||||||
|
double range = 5.0;
|
||||||
|
|
||||||
|
struct point points[] = {
|
||||||
|
{ 11.0, 11.0 },
|
||||||
|
{ 10.0, 10.0 },
|
||||||
|
{ 20.0, 20.0 },
|
||||||
|
{ 14.0, 13.0 }
|
||||||
|
};
|
||||||
|
|
||||||
|
size_t size = sizeof(points) / sizeof(struct point);
|
||||||
|
|
||||||
|
size_t found = detect_points(center, range, points, size);
|
||||||
|
printf("Total found: %zu\n", found);
|
||||||
|
|
||||||
|
}
|
||||||
31
HolidayTrip/Fundamentals/radar/radar.c
Normal file
31
HolidayTrip/Fundamentals/radar/radar.c
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
#include "radar.h"
|
||||||
|
#include <stddef.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
|
double compute_distance(struct point a, struct point b){
|
||||||
|
|
||||||
|
return sqrt( pow((b.x - a.x),2) + pow((b.y - a.y),2) );
|
||||||
|
}
|
||||||
|
|
||||||
|
int is_in_area(struct point center, double radius, struct point point){
|
||||||
|
|
||||||
|
int rslt = compute_distance(center, point);
|
||||||
|
|
||||||
|
if(rslt > radius) return 0;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t detect_points(struct point center, double range, struct point *interesting_points, size_t nb_points){
|
||||||
|
|
||||||
|
size_t found = 0;
|
||||||
|
for(size_t i = 0; i < nb_points; i++){
|
||||||
|
|
||||||
|
if(is_in_area(center, range,interesting_points[i]) == 1){
|
||||||
|
printf("{ %f, %f }\n",interesting_points[i].x, interesting_points[i].y);
|
||||||
|
found ++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return found;
|
||||||
|
}
|
||||||
16
HolidayTrip/Fundamentals/radar/radar.h
Normal file
16
HolidayTrip/Fundamentals/radar/radar.h
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
#ifndef RADAR_H
|
||||||
|
#define RADAR_H
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
struct point
|
||||||
|
{
|
||||||
|
double x;
|
||||||
|
double y;
|
||||||
|
};
|
||||||
|
|
||||||
|
double compute_distance(struct point a, struct point b);
|
||||||
|
int is_in_area(struct point center, double radius, struct point point);
|
||||||
|
size_t detect_points(struct point center, double range, struct point* interesting_points, size_t nb_points);
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
||||||
16
HolidayTrip/Fundamentals/reap_and_tear/Makefile
Normal file
16
HolidayTrip/Fundamentals/reap_and_tear/Makefile
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
CC=gcc
|
||||||
|
SRC = villager.c demon.c weapons.c print.c main.c
|
||||||
|
CFLAGS= -Wall -Wextra -Werror
|
||||||
|
LDFLAGS= -fsanitize=address -g -lm
|
||||||
|
|
||||||
|
# Computes the basic main for tests
|
||||||
|
main: ${SRC}
|
||||||
|
gcc $(CFLAGS) $^ -o main -lm
|
||||||
|
|
||||||
|
#Check for memory errors/leaks and to use gdb
|
||||||
|
debug: ${SRC}
|
||||||
|
gcc $(CFLAGS) $^ -o debug $(LDFLAGS)
|
||||||
|
|
||||||
|
clean:
|
||||||
|
$(RM) main debug
|
||||||
|
|
||||||
0
HolidayTrip/Fundamentals/reap_and_tear/demon.c
Normal file
0
HolidayTrip/Fundamentals/reap_and_tear/demon.c
Normal file
37
HolidayTrip/Fundamentals/reap_and_tear/demon.h
Normal file
37
HolidayTrip/Fundamentals/reap_and_tear/demon.h
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
#ifndef DEMON_H
|
||||||
|
#define DEMON_H
|
||||||
|
|
||||||
|
#include "villager.h"
|
||||||
|
|
||||||
|
struct villager;
|
||||||
|
|
||||||
|
enum demon_category
|
||||||
|
{
|
||||||
|
PARASITE = 1,
|
||||||
|
THREAT,
|
||||||
|
NIGHTMARE,
|
||||||
|
CALAMITY,
|
||||||
|
TOM_NOOK
|
||||||
|
};
|
||||||
|
|
||||||
|
struct demon {
|
||||||
|
enum demon_category category;
|
||||||
|
char name[50];
|
||||||
|
int damage;
|
||||||
|
enum distance range;
|
||||||
|
int cur_HP;
|
||||||
|
int HP_max;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct demon *init_demon(enum demon_category category, char name[50], int HP_max, int damage, enum distance range);
|
||||||
|
void pp_demon(struct demon *demon);
|
||||||
|
void destroy_demon(struct demon *demon);
|
||||||
|
void basic_attack(struct demon *demon, struct villager *target);
|
||||||
|
void draining_attack(struct demon *demon, struct villager *target);
|
||||||
|
void heavy_attack(struct demon *demon, struct villager *target);
|
||||||
|
void chase(struct demon *demon, struct villager *villager);
|
||||||
|
void update_demon_hp(struct demon *demon, int amount);
|
||||||
|
void demon_action(struct demon *demon, struct villager *villager);
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
||||||
BIN
HolidayTrip/Fundamentals/reap_and_tear/main
Executable file
BIN
HolidayTrip/Fundamentals/reap_and_tear/main
Executable file
Binary file not shown.
14
HolidayTrip/Fundamentals/reap_and_tear/main.c
Normal file
14
HolidayTrip/Fundamentals/reap_and_tear/main.c
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#include "demon.h"
|
||||||
|
#include "villager.h"
|
||||||
|
#include "weapons.h"
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
char gun_name[50] = "BFG";
|
||||||
|
struct gun *gun = init_gun(gun_name, 50, FAR, 16);
|
||||||
|
|
||||||
|
printf("Gun name: %s\nDamage: %d\nRange: %d\nMagazine: %d/%d\n", gun->name, gun->damage, gun->range, gun->current_magazine, gun->magazine_size);
|
||||||
|
|
||||||
|
}
|
||||||
0
HolidayTrip/Fundamentals/reap_and_tear/print.c
Normal file
0
HolidayTrip/Fundamentals/reap_and_tear/print.c
Normal file
0
HolidayTrip/Fundamentals/reap_and_tear/villager.c
Normal file
0
HolidayTrip/Fundamentals/reap_and_tear/villager.c
Normal file
28
HolidayTrip/Fundamentals/reap_and_tear/villager.h
Normal file
28
HolidayTrip/Fundamentals/reap_and_tear/villager.h
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
#ifndef VILLAGER_H
|
||||||
|
#define VILLAGER_H
|
||||||
|
|
||||||
|
#include "weapons.h"
|
||||||
|
struct demon;
|
||||||
|
|
||||||
|
struct villager{
|
||||||
|
char name[50];
|
||||||
|
int cur_HP;
|
||||||
|
int HP_max;
|
||||||
|
// struct gun;
|
||||||
|
int gun_mastery;
|
||||||
|
int medicines;
|
||||||
|
enum distance distance;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct villager *init_villager(char name[50], int HP_max, struct gun *gun, int gun_mastery);
|
||||||
|
void pp_villager(struct villager *villager);
|
||||||
|
void destroy_villager(struct villager *villager);
|
||||||
|
void update_villager_hp(struct villager *villager, int amount);
|
||||||
|
void shoot(struct villager *villager, struct demon *demon);
|
||||||
|
void heal(struct villager *villager);
|
||||||
|
enum distance walk(struct villager *villager, int direction);
|
||||||
|
int prepare_medicine(struct villager *villager);
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
17
HolidayTrip/Fundamentals/reap_and_tear/weapons.c
Normal file
17
HolidayTrip/Fundamentals/reap_and_tear/weapons.c
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
#include "weapons.h"
|
||||||
|
#include <stddef.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
struct gun *init_gun(char name[50], int damage, enum distance range, int magazine_size){
|
||||||
|
|
||||||
|
struct gun *rslt = malloc(sizeof( struct gun));
|
||||||
|
//mettre protection
|
||||||
|
|
||||||
|
//init des var du struct
|
||||||
|
strcpy(rslt->name, name);
|
||||||
|
rslt->damage = damage;
|
||||||
|
rslt->range = range;
|
||||||
|
rslt->magazine_size = magazine_size;
|
||||||
|
|
||||||
|
return rslt;
|
||||||
|
}
|
||||||
24
HolidayTrip/Fundamentals/reap_and_tear/weapons.h
Normal file
24
HolidayTrip/Fundamentals/reap_and_tear/weapons.h
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
#ifndef WEAPONS_H
|
||||||
|
#define WEAPONS_H
|
||||||
|
|
||||||
|
enum distance
|
||||||
|
{
|
||||||
|
CLOSE,
|
||||||
|
NEAR,
|
||||||
|
FAR,
|
||||||
|
};
|
||||||
|
|
||||||
|
struct gun {
|
||||||
|
char name[50];
|
||||||
|
int damage;
|
||||||
|
enum distance range;
|
||||||
|
int magazine_size;
|
||||||
|
int current_magazine;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct gun *init_gun(char name[50], int damage, enum distance range, int magazine_size);
|
||||||
|
void reload(struct gun *gun);
|
||||||
|
void destroy_gun(struct gun *gun);
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
||||||
14
HolidayTrip/Proficiencies/animals/Makefile
Normal file
14
HolidayTrip/Proficiencies/animals/Makefile
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
CC=gcc
|
||||||
|
SRC = fish.c insects.c vector.c main.c
|
||||||
|
CFLAGS= -Wall -Wextra -Werror
|
||||||
|
LDFLAGS= -fsanitize=address -g
|
||||||
|
# Computes the basic main for tests
|
||||||
|
main: ${SRC}
|
||||||
|
gcc $(CFLAGS) $^ -o main -lm
|
||||||
|
|
||||||
|
#Check for memory errors/leaks and to use gdb
|
||||||
|
debug: ${SRC}
|
||||||
|
gcc $(CFLAGS) $^ -o debug $(LDFLAGS)
|
||||||
|
|
||||||
|
clean:
|
||||||
|
$(RM) main debug
|
||||||
0
HolidayTrip/Proficiencies/animals/animals.h
Normal file
0
HolidayTrip/Proficiencies/animals/animals.h
Normal file
0
HolidayTrip/Proficiencies/animals/fish.c
Normal file
0
HolidayTrip/Proficiencies/animals/fish.c
Normal file
0
HolidayTrip/Proficiencies/animals/insect.c
Normal file
0
HolidayTrip/Proficiencies/animals/insect.c
Normal file
7
HolidayTrip/Proficiencies/animals/main.c
Normal file
7
HolidayTrip/Proficiencies/animals/main.c
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#include "animals.h"
|
||||||
|
#include "vector.h"
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{}
|
||||||
0
HolidayTrip/Proficiencies/animals/vector.c
Normal file
0
HolidayTrip/Proficiencies/animals/vector.c
Normal file
0
HolidayTrip/Proficiencies/animals/vector.h
Normal file
0
HolidayTrip/Proficiencies/animals/vector.h
Normal file
14
HolidayTrip/Proficiencies/museum_restoration/Makefile
Normal file
14
HolidayTrip/Proficiencies/museum_restoration/Makefile
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
CC=gcc
|
||||||
|
SRC = fossils.c main.c
|
||||||
|
CFLAGS= -Wall -Wextra -Werror
|
||||||
|
LDFLAGS= -fsanitize=address -g
|
||||||
|
# Computes the basic main for tests
|
||||||
|
main: ${SRC}
|
||||||
|
gcc $(CFLAGS) $^ -o main -lm
|
||||||
|
|
||||||
|
#Check for memory errors/leaks and to use gdb
|
||||||
|
debug: ${SRC}
|
||||||
|
gcc $(CFLAGS) $^ -o debug $(LDFLAGS)
|
||||||
|
|
||||||
|
clean:
|
||||||
|
$(RM) main debug
|
||||||
6
HolidayTrip/Proficiencies/museum_restoration/main.c
Normal file
6
HolidayTrip/Proficiencies/museum_restoration/main.c
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#include "fossils.h"
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{}
|
||||||
Reference in New Issue
Block a user