Skip to content
Snippets Groups Projects
Commit f81655e9 authored by iliya's avatar iliya
Browse files

ex3 finished

parent ef8cbfd9
No related branches found
No related tags found
No related merge requests found
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)
File added
#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;
}
File added
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment