diff --git a/serie1/ex3/Makefile b/serie1/ex3/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..b8cbbd64136ccba9baf2dfecabde09143c7042e8 --- /dev/null +++ b/serie1/ex3/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/ex3/prog b/serie1/ex3/prog new file mode 100755 index 0000000000000000000000000000000000000000..a52807727d7ee2d57214cb7315cab705420bf3e5 Binary files /dev/null and b/serie1/ex3/prog differ diff --git a/serie1/ex3/prog.c b/serie1/ex3/prog.c new file mode 100644 index 0000000000000000000000000000000000000000..53b6bb8ccfdc00ef2498e2be52333b19bddfe049 --- /dev/null +++ b/serie1/ex3/prog.c @@ -0,0 +1,27 @@ +#include <stddef.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +char *invert_string(char *str, size_t len) { + + char *ret = calloc(len + 1, sizeof(char)); + + for (size_t i = 0; i < len; i++) { + ret[i] = str[len - 1 - i]; + } + + return ret; +} + +int main(void) { + + char *my_str = "Lorem Ipsum"; + + char *inverted = invert_string(my_str, strlen(my_str)); + + fprintf(stdout, "New string: %s\n", inverted); + + free(inverted); + return EXIT_SUCCESS; +} diff --git a/serie1/ex3/prog.o b/serie1/ex3/prog.o new file mode 100644 index 0000000000000000000000000000000000000000..92b8f4418d10e9c5ada318c5be8d2204316a45eb Binary files /dev/null and b/serie1/ex3/prog.o differ