diff options
| author | Charles <sircharlesaze@gmail.com> | 2019-07-15 10:20:37 +0200 |
|---|---|---|
| committer | Charles <sircharlesaze@gmail.com> | 2019-07-15 10:20:37 +0200 |
| commit | 217bcb0d4e3ba60604921cb40d5a11a64f93cfc7 (patch) | |
| tree | 32a8f1f84e0b5f3617988932ccc068d471207208 /c09/ex01 | |
| parent | 3b9a1d7dcc5683b962f2bf24795e80e1c449cd1f (diff) | |
| download | piscine-217bcb0d4e3ba60604921cb40d5a11a64f93cfc7.tar.gz piscine-217bcb0d4e3ba60604921cb40d5a11a64f93cfc7.tar.bz2 piscine-217bcb0d4e3ba60604921cb40d5a11a64f93cfc7.zip | |
c08 strdup malloc + 1 for \0, c09 begin
Diffstat (limited to 'c09/ex01')
| -rw-r--r-- | c09/ex01/Makefile | 30 | ||||
| -rw-r--r-- | c09/ex01/includes/ft.h | 22 | ||||
| -rw-r--r-- | c09/ex01/srcs/ft_putchar.c | 18 | ||||
| -rw-r--r-- | c09/ex01/srcs/ft_putstr.c | 19 | ||||
| -rw-r--r-- | c09/ex01/srcs/ft_strcmp.c | 21 | ||||
| -rw-r--r-- | c09/ex01/srcs/ft_strlen.c | 21 | ||||
| -rw-r--r-- | c09/ex01/srcs/ft_swap.c | 20 |
7 files changed, 140 insertions, 11 deletions
diff --git a/c09/ex01/Makefile b/c09/ex01/Makefile index 0fec395..ba69535 100644 --- a/c09/ex01/Makefile +++ b/c09/ex01/Makefile @@ -1,28 +1,36 @@ -SRCDIR = srcs -SRC = ft_putchar.c ft_swap.c ft_putstr.c ft_strlen.c ft_strcmp.c -OBJ = $(SRC:.c = .o) -INCLUDEDIR = includes -INCLUDES = ft.h +OUT = libft.a CC = gcc CCFLAGS = -Wall -Wextra -Werror -OUT = libft.a +OBJ = srcs/ft_putchar.o srcs/ft_swap.o srcs/ft_putstr.o srcs/ft_strlen.o srcs/ft_strcmp.o -all: OUT .PHONY: all +all: $(OUT) $(OUT): $(OBJ) - ar -crs $(OBJ) + ar -crs $(OUT) $(OBJ) + +srcs/ft_putchar.o: srcs/ft_putchar.c includes/ft.h + $(CC) $(CCFLAGS) -c $< -o $@ + +srcs/ft_swap.o: srcs/ft_swap.c includes/ft.h + $(CC) $(CCFLAGS) -c $< -o $@ + +srcs/ft_putstr.o: srcs/ft_putstr.c includes/ft.h + $(CC) $(CCFLAGS) -c $< -o $@ + +srcs/ft_strlen.o: srcs/ft_strlen.c includes/ft.h + $(CC) $(CCFLAGS) -c $< -o $@ -$(OBJ): %.o: %.c +srcs/ft_strcmp.o: srcs/ft_strcmp.c includes/ft.h $(CC) $(CCFLAGS) -c $< -o $@ .PHONY: clean clean: - rm -f srcs/*.o + rm -f $(OBJ) .PHONY: fclean fclean: clean - rm $(OUT) + rm -f $(OUT) .PHONY: re re: fclean all diff --git a/c09/ex01/includes/ft.h b/c09/ex01/includes/ft.h new file mode 100644 index 0000000..e044fdd --- /dev/null +++ b/c09/ex01/includes/ft.h @@ -0,0 +1,22 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle <charles.cabergs@gmail.com> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/07/15 08:52:33 by cacharle #+# #+# */ +/* Updated: 2019/07/15 09:12:41 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef FT_H +# define FT_H + +void ft_putchar(char c); +void ft_swap(int *a, int *b); +void ft_putstr(char *str); +int ft_strlen(char *str); +int ft_strcmp(char *s1, char *s2); + +#endif diff --git a/c09/ex01/srcs/ft_putchar.c b/c09/ex01/srcs/ft_putchar.c new file mode 100644 index 0000000..8a53dc8 --- /dev/null +++ b/c09/ex01/srcs/ft_putchar.c @@ -0,0 +1,18 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_putchar.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle <charles.cabergs@gmail.com> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/07/02 22:03:32 by cacharle #+# #+# */ +/* Updated: 2019/07/03 14:21:40 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include <unistd.h> + +void ft_putchar(char c) +{ + write(1, &c, 1); +} diff --git a/c09/ex01/srcs/ft_putstr.c b/c09/ex01/srcs/ft_putstr.c new file mode 100644 index 0000000..c4f4564 --- /dev/null +++ b/c09/ex01/srcs/ft_putstr.c @@ -0,0 +1,19 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_putstr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle <charles.cabergs@gmail.com> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/07/11 16:17:16 by cacharle #+# #+# */ +/* Updated: 2019/07/11 16:18:11 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include <unistd.h> + +void ft_putstr(char *str) +{ + while (*str) + write(1, str++, 1); +} diff --git a/c09/ex01/srcs/ft_strcmp.c b/c09/ex01/srcs/ft_strcmp.c new file mode 100644 index 0000000..7b96c2e --- /dev/null +++ b/c09/ex01/srcs/ft_strcmp.c @@ -0,0 +1,21 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strcmp.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle <charles.cabergs@gmail.com> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/07/11 16:20:33 by cacharle #+# #+# */ +/* Updated: 2019/07/15 09:09:49 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_strcmp(char *s1, char *s2) +{ + while (*s1 == *s2 && *s1 && *s2) + { + s1++; + s2++; + } + return (*s1 - *s2); +} diff --git a/c09/ex01/srcs/ft_strlen.c b/c09/ex01/srcs/ft_strlen.c new file mode 100644 index 0000000..8c6ba48 --- /dev/null +++ b/c09/ex01/srcs/ft_strlen.c @@ -0,0 +1,21 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strlen.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle <charles.cabergs@gmail.com> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/07/11 16:19:43 by cacharle #+# #+# */ +/* Updated: 2019/07/15 08:54:14 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_strlen(char *str) +{ + int i; + + i = 0; + while (str[i]) + i++; + return (i); +} diff --git a/c09/ex01/srcs/ft_swap.c b/c09/ex01/srcs/ft_swap.c new file mode 100644 index 0000000..989b2c2 --- /dev/null +++ b/c09/ex01/srcs/ft_swap.c @@ -0,0 +1,20 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_swap.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle <charles.cabergs@gmail.com> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/07/11 16:18:42 by cacharle #+# #+# */ +/* Updated: 2019/07/11 16:19:31 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +void ft_swap(int *a, int *b) +{ + int tmp; + + tmp = *a; + *a = *b; + *b = tmp; +} |
