From c629a9941242eb0e6d70034aab95739dee304d96 Mon Sep 17 00:00:00 2001 From: Baco Date: Tue, 24 Aug 2021 20:55:48 +0200 Subject: [PATCH] commit --- C_09/git/ex01/Makefile | 30 +++++++++++++++--------------- C_09/git/ex01/main.c | 7 +------ C_09/git/ex01/main.sh | 4 ++-- C_09/git/ex02/ft_split.c | 17 ++++++++++------- C_09/git/ex02/main.c | 17 ++++++++++------- C_09/git/ex02/main.sh | 2 +- 6 files changed, 39 insertions(+), 38 deletions(-) diff --git a/C_09/git/ex01/Makefile b/C_09/git/ex01/Makefile index 02d7b20..3dac316 100644 --- a/C_09/git/ex01/Makefile +++ b/C_09/git/ex01/Makefile @@ -18,33 +18,33 @@ NAME = libft.a SRCDIR = srcs +SRC = $(SRCDIR)/ft_putchar.c $(SRCDIR)/ft_swap.c $(SRCDIR)/ft_putstr.c $(SRCDIR)/ft_strlen.c $(SRCDIR)/ft_strcmp.c +OBJ = ${SRC:.c=.o} -SRC = ft_putchar.c \ - ft_swap.c \ - ft_putstr.c \ - ft_strlen.c \ - ft_strcmp.c - -HDR = ft.h - -INCLUDE = includes +HDRDIR = includes +HDR = $(HDRDIR)/ft.h CC = gcc CFLAGS = -Wall -Wextra -Werror AR = ar -ARFLAGS = -cq +ARFLAGS = -rcs + +RM = rm +RMFLAGS = -f all: $(NAME) -$(NAME): - cd $(SRCDIR) && $(CC) $(CFLAGS) -I $(INCLUDE) -c $(SRC) - $(AR) $(ARFLAGS) $(NAME) $(SRCDIR)/*.o +.c.o: + $(CC) $(CFLAGS) -I $(HDRDIR) -c $< -o ${<:.c=.o} + +$(NAME): $(OBJ) + $(AR) $(ARFLAGS) $@ $^ clean: - @/bin/rm -f **/*.o + $(RM) $(RMFLAGS) $(OBJ) fclean: clean - @/bin/rm -f $(NAME) + $(RM) $(RMFLAGS) $(NAME) re: fclean all diff --git a/C_09/git/ex01/main.c b/C_09/git/ex01/main.c index bc1c4cc..82f98f6 100644 --- a/C_09/git/ex01/main.c +++ b/C_09/git/ex01/main.c @@ -14,12 +14,7 @@ #include #include #include - -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); +#include "ft.h" int main(void) { diff --git a/C_09/git/ex01/main.sh b/C_09/git/ex01/main.sh index 83595c0..c6ee0fb 100755 --- a/C_09/git/ex01/main.sh +++ b/C_09/git/ex01/main.sh @@ -7,9 +7,9 @@ norminette -R CheckForbiddenSourceHeader {} \; echo make fclean make -rm -f *.o echo echo $(basename $PWD): -gcc -Wall -Wextra -Werror -o a.out -L. -lft main.c +gcc -Wall -Wextra -Werror main.c -I includes -L . -lft -o a.out ./a.out "$@" +make fclean rm -f a.out diff --git a/C_09/git/ex02/ft_split.c b/C_09/git/ex02/ft_split.c index bc28908..ae3bee8 100644 --- a/C_09/git/ex02/ft_split.c +++ b/C_09/git/ex02/ft_split.c @@ -28,19 +28,22 @@ static char *ft_strncpy(char *dest, char *src, unsigned int n) dest[i] = '\0'; i++; } + dest[i] = '\0'; return (dest); } static int ft_is_charset(char c, char *charset) { - char *p_charset; - int r; + int i; - r = 0; - p_charset = charset; - while (*p_charset != '\0') - r |= (*p_charset++ == c); - return (r); + i = 0; + while (charset[i] != '\0') + { + if (c == charset[i]) + return (1); + i++; + } + return (0); } static int ft_split_len(char *str, char *charset) diff --git a/C_09/git/ex02/main.c b/C_09/git/ex02/main.c index 97abb88..7a70667 100644 --- a/C_09/git/ex02/main.c +++ b/C_09/git/ex02/main.c @@ -17,17 +17,20 @@ char **ft_split(char *str, char *charset); -int main(void) +int main(int argc, char *argv[]) { - char str[32]; - char charset[32]; + char *str; + char *charset; char **strs; int i; - printf("Input String [Max 32]: "); - scanf("%s", str); - printf("Input Charset [Max 32]: "); - scanf("%s", charset); + if (argc < 2) + { + printf("%s \n", argv[0]); + return (1); + } + str = argv[1]; + charset = argv[2]; strs = ft_split(str, charset); printf("str=%s charset=%s (ft_split)\n", str, charset); i = 0; diff --git a/C_09/git/ex02/main.sh b/C_09/git/ex02/main.sh index 3042505..a551eac 100755 --- a/C_09/git/ex02/main.sh +++ b/C_09/git/ex02/main.sh @@ -5,5 +5,5 @@ rm -f a.out norminette -R CheckForbiddenSourceHeader gcc -Wall -Wextra -Werror -o a.out *.c echo $(basename $PWD): -./a.out +./a.out "$@" rm -f a.out