diff --git a/serie1/ex2/.gitignore b/serie1/ex2/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..b6de771d2fff3a218dbc1b3de5b6b6cc1dc54e08 --- /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 0000000000000000000000000000000000000000..b8cbbd64136ccba9baf2dfecabde09143c7042e8 --- /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 0000000000000000000000000000000000000000..0ee192fecf0fcdda2cff0f5288735ce8087ebb40 --- /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; +}