From ef8cbfd95b852fb992120b7a6e7dc53bf38fefd4 Mon Sep 17 00:00:00 2001 From: iliya <iliya.saroukha@hes-so.ch> Date: Wed, 27 Sep 2023 10:54:41 +0200 Subject: [PATCH] ex2 finished, feat mes beaux commit @ JAD --- serie1/ex2/.gitignore | 2 ++ serie1/ex2/Makefile | 19 +++++++++++++++++++ serie1/ex2/prog.c | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 54 insertions(+) create mode 100644 serie1/ex2/.gitignore create mode 100644 serie1/ex2/Makefile create mode 100644 serie1/ex2/prog.c diff --git a/serie1/ex2/.gitignore b/serie1/ex2/.gitignore new file mode 100644 index 0000000..b6de771 --- /dev/null +++ b/serie1/ex2/.gitignore @@ -0,0 +1,2 @@ +*.o +prog diff --git a/serie1/ex2/Makefile b/serie1/ex2/Makefile new file mode 100644 index 0000000..b8cbbd6 --- /dev/null +++ b/serie1/ex2/Makefile @@ -0,0 +1,19 @@ +CC := clang +CFLAGS := -g -pedantic -Wall -Wextra -std=c2x +LDFLAGS := -fsanitize=address -fsanitize=leak -fsanitize=undefined -lm +TARGET := prog + +all: $(TARGET) + +$(TARGET): prog.o + @printf "=================== Building executable ===================\n" + $(CC) $(CFLAGS) $^ -o $@ $(LDFLAGS) + @printf "\n" + +%.o: %.c + @printf "================== Building object files ==================\n" + $(CC) $(CFLAGS) -c $< + @printf "\n" + +clean: + rm -f *.o $(TARGET) diff --git a/serie1/ex2/prog.c b/serie1/ex2/prog.c new file mode 100644 index 0000000..0ee192f --- /dev/null +++ b/serie1/ex2/prog.c @@ -0,0 +1,33 @@ +#include <stddef.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +typedef struct { + char *str; + char replacing_space; +} str_space_replaced; + +void replace_space(str_space_replaced *str) { + for (size_t i = 0; i < strlen(str->str); i++) { + fprintf(stderr, "%c\n", str->str[i]); + if (str->str[i] == ' ') { + str->str[i] = str->replacing_space; + } + } +} + +int main(void) { + char my_str[] = "Lorem ipsum dolor imet"; + + str_space_replaced str = { + .str = my_str, + .replacing_space = 'A', + }; + + replace_space(&str); + + fprintf(stdout, "New string: %s\n", str.str); + + return EXIT_SUCCESS; +} -- GitLab