sync
This commit is contained in:
BIN
C_08/c-08.tar
BIN
C_08/c-08.tar
Binary file not shown.
@@ -11,7 +11,7 @@
|
||||
#
|
||||
|
||||
clone:
|
||||
@git clone git@vogsphere.42lausanne.ch:vogsphere/intra-uuid-c788fb82-b004-4075-9eed-e90d2aa94bc7-3745071 git
|
||||
@git clone git@vogsphere.42lausanne.ch:vogsphere/intra-uuid-27c9dbdb-d7d5-4a65-88f3-b649e102aa89-3748576 git
|
||||
|
||||
cc:
|
||||
@norminette -R CheckForbiddenSourceHeader
|
||||
|
||||
BIN
C_09/c-09.tar
BIN
C_09/c-09.tar
Binary file not shown.
BIN
C_09/git/ex00/ft_putchar.o
Normal file
BIN
C_09/git/ex00/ft_putchar.o
Normal file
Binary file not shown.
BIN
C_09/git/ex00/ft_putstr.o
Normal file
BIN
C_09/git/ex00/ft_putstr.o
Normal file
Binary file not shown.
BIN
C_09/git/ex00/ft_strcmp.o
Normal file
BIN
C_09/git/ex00/ft_strcmp.o
Normal file
Binary file not shown.
BIN
C_09/git/ex00/ft_strlen.o
Normal file
BIN
C_09/git/ex00/ft_strlen.o
Normal file
Binary file not shown.
BIN
C_09/git/ex00/ft_swap.o
Normal file
BIN
C_09/git/ex00/ft_swap.o
Normal file
Binary file not shown.
BIN
C_09/git/ex00/libft.a
Normal file
BIN
C_09/git/ex00/libft.a
Normal file
Binary file not shown.
@@ -1,6 +1,4 @@
|
||||
#!/bin/sh
|
||||
rm -f *.o libft.a
|
||||
gcc -Wall -Wextra -Werror -c *.c
|
||||
ar -cq libft.a *.o
|
||||
#ar -t libft.a
|
||||
#rm -f *.o
|
||||
gcc -Wall -Wextra -Werror -c ft_putchar.c ft_swap.c ft_putstr.c ft_strlen.c ft_strcmp.c
|
||||
ar -rcs libft.a ft_putchar.o ft_swap.o ft_putstr.o ft_strlen.o ft_strcmp.o
|
||||
|
||||
@@ -8,7 +8,9 @@ echo
|
||||
sh libft_creator.sh
|
||||
rm -f *.o
|
||||
echo
|
||||
echo $(basename $PWD):
|
||||
gcc -Wall -Wextra -Werror -o a.out -L. -lft main.c
|
||||
ar -t libft.a
|
||||
echo
|
||||
echo $(basename $PWD):
|
||||
./a.out "$@"
|
||||
rm -f a.out
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
# By: gbaconni <gbaconni@42lausanne.ch> +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# Created: 2021/08/22 17:28:57 by gbaconni #+# #+# #
|
||||
# Updated: 2021/08/22 18:12:53 by gbaconni ### ########.fr #
|
||||
# Updated: 2021/08/26 11:41:39 by gbaconni ### ########.fr #
|
||||
# #
|
||||
# **************************************************************************** #
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
/* By: gbaconni <gbaconni@42lausanne.ch> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2021/08/22 18:14:04 by gbaconni #+# #+# */
|
||||
/* Updated: 2021/08/26 09:53:30 by gbaconni ### ########.fr */
|
||||
/* Updated: 2021/08/26 11:46:51 by gbaconni ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -75,7 +75,7 @@ char *ft_copy(char *str, int size)
|
||||
if (size > 0)
|
||||
ft_strncpy(result, str, size);
|
||||
else
|
||||
result[0] = '\0';
|
||||
result = 0;
|
||||
return (result);
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
/* By: gbaconni <gbaconni@42lausanne.ch> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2021/08/18 10:50:59 by gbaconni #+# #+# */
|
||||
/* Updated: 2021/08/25 14:11:02 by gbaconni ### ########.fr */
|
||||
/* Updated: 2021/08/26 11:45:37 by gbaconni ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
||||
21
C_09/git_old/ex00/ft.h
Normal file
21
C_09/git_old/ex00/ft.h
Normal file
@@ -0,0 +1,21 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gbaconni <gbaconni@42lausanne.ch> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2021/08/20 10:17:09 by gbaconni #+# #+# */
|
||||
/* Updated: 2021/08/20 12:05:50 by gbaconni ### ########.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
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -14,12 +14,7 @@
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.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);
|
||||
#include "ft.h"
|
||||
|
||||
int main(void)
|
||||
{
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -6,13 +6,15 @@
|
||||
/* By: gbaconni <gbaconni@42lausanne.ch> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2021/08/22 18:14:04 by gbaconni #+# #+# */
|
||||
/* Updated: 2021/08/24 13:00:34 by gbaconni ### ########.fr */
|
||||
/* Updated: 2021/08/26 09:53:30 by gbaconni ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
int g_t = 0;
|
||||
|
||||
static char *ft_strncpy(char *dest, char *src, unsigned int n)
|
||||
{
|
||||
unsigned int i;
|
||||
@@ -28,19 +30,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)
|
||||
@@ -49,6 +54,8 @@ static int ft_split_len(char *str, char *charset)
|
||||
int size;
|
||||
|
||||
size = 2;
|
||||
if (str == NULL || charset == NULL)
|
||||
return (size);
|
||||
p_str = str;
|
||||
while (*p_str != '\0')
|
||||
{
|
||||
@@ -63,6 +70,8 @@ char *ft_copy(char *str, int size)
|
||||
char *result;
|
||||
|
||||
result = (char *) malloc((size + 1) * sizeof(char));
|
||||
if (!result)
|
||||
return (NULL);
|
||||
if (size > 0)
|
||||
ft_strncpy(result, str, size);
|
||||
else
|
||||
@@ -74,24 +83,25 @@ char **ft_split(char *str, char *charset)
|
||||
{
|
||||
char **strs;
|
||||
char *start;
|
||||
int size;
|
||||
int i;
|
||||
|
||||
size = ft_split_len(str, charset);
|
||||
strs = malloc((size) * sizeof(strs));
|
||||
strs = malloc(ft_split_len(str, charset) * sizeof(strs));
|
||||
if (strs == NULL || charset == NULL || str == NULL)
|
||||
return (NULL);
|
||||
start = str;
|
||||
i = 0;
|
||||
while (1)
|
||||
{
|
||||
if (ft_is_charset(*str, charset) == 1 || *str == '\0')
|
||||
if (ft_is_charset(*str, charset) == 1 || (*str == '\0' && g_t > 0))
|
||||
{
|
||||
size = str - start;
|
||||
if (size > 0)
|
||||
strs[i++] = ft_copy(start, size);
|
||||
if (str - start > 0)
|
||||
strs[i++] = ft_copy(start, str - start);
|
||||
start = str + 1;
|
||||
}
|
||||
else
|
||||
g_t++;
|
||||
if (*str == '\0')
|
||||
break ;
|
||||
}
|
||||
str++;
|
||||
}
|
||||
strs[i] = ft_copy(str, 0);
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
/* By: gbaconni <gbaconni@42lausanne.ch> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2021/08/18 10:50:59 by gbaconni #+# #+# */
|
||||
/* Updated: 2021/08/24 11:56:21 by gbaconni ### ########.fr */
|
||||
/* Updated: 2021/08/25 14:11:02 by gbaconni ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -17,24 +17,30 @@
|
||||
|
||||
char **ft_split(char *str, char *charset);
|
||||
|
||||
int main(void)
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
char str[32];
|
||||
char charset[32];
|
||||
char **strs;
|
||||
char *str;
|
||||
char *charset;
|
||||
int i;
|
||||
|
||||
printf("Input String [Max 32]: ");
|
||||
scanf("%s", str);
|
||||
printf("Input Charset [Max 32]: ");
|
||||
scanf("%s", charset);
|
||||
if (argc < 2)
|
||||
{
|
||||
printf("%s <str> <charset>\n", argv[0]);
|
||||
return (1);
|
||||
}
|
||||
str = argv[1];
|
||||
charset = argv[2];
|
||||
if (str[0] == '\0')
|
||||
str = NULL;
|
||||
strs = ft_split(str, charset);
|
||||
printf("str=%s charset=%s (ft_split)\n", str, charset);
|
||||
i = 0;
|
||||
while (strs[i][0] != '\0')
|
||||
while (strs[i])
|
||||
{
|
||||
printf("strs[%d] = %s\n", i, strs[i]);
|
||||
i++;
|
||||
}
|
||||
free(strs);
|
||||
return (0);
|
||||
}
|
||||
|
||||
@@ -3,7 +3,8 @@ set -e
|
||||
rm -f a.out
|
||||
#norminette -R CheckForbiddenSourceHeader ft_*.c
|
||||
norminette -R CheckForbiddenSourceHeader
|
||||
#gcc -Wall -Wextra -Werror -fsanitize=address -g -o a.out *.c
|
||||
gcc -Wall -Wextra -Werror -o a.out *.c
|
||||
echo $(basename $PWD):
|
||||
./a.out
|
||||
./a.out "$@"
|
||||
rm -f a.out
|
||||
|
||||
18
C_09/git_old2/ex00/ft_putchar.c
Normal file
18
C_09/git_old2/ex00/ft_putchar.c
Normal file
@@ -0,0 +1,18 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_putchar.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gbaconni <gbaconni@42lausanne.ch> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2021/08/22 14:41:08 by gbaconni #+# #+# */
|
||||
/* Updated: 2021/08/22 14:41:17 by gbaconni ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
void ft_putchar(char c)
|
||||
{
|
||||
write(1, &c, 1);
|
||||
}
|
||||
22
C_09/git_old2/ex00/ft_putstr.c
Normal file
22
C_09/git_old2/ex00/ft_putstr.c
Normal file
@@ -0,0 +1,22 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_putstr.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gbaconni <gbaconni@42lausanne.ch> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2021/08/22 14:42:02 by gbaconni #+# #+# */
|
||||
/* Updated: 2021/08/22 14:42:04 by gbaconni ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
void ft_putstr(char *str)
|
||||
{
|
||||
char *p_str;
|
||||
|
||||
p_str = str;
|
||||
while (*p_str != '\0')
|
||||
write(1, p_str++, 1);
|
||||
}
|
||||
28
C_09/git_old2/ex00/ft_strcmp.c
Normal file
28
C_09/git_old2/ex00/ft_strcmp.c
Normal file
@@ -0,0 +1,28 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strcmp.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gbaconni <gbaconni@42lausanne.ch> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2021/08/22 14:43:35 by gbaconni #+# #+# */
|
||||
/* Updated: 2021/08/22 14:43:44 by gbaconni ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
int ft_strcmp(char *s1, char *s2)
|
||||
{
|
||||
char c1;
|
||||
char c2;
|
||||
|
||||
c1 = '\0';
|
||||
c2 = '\0';
|
||||
while (c1 == c2)
|
||||
{
|
||||
c1 = *s1++;
|
||||
c2 = *s2++;
|
||||
if (c1 == '\0')
|
||||
break ;
|
||||
}
|
||||
return (c1 - c2);
|
||||
}
|
||||
21
C_09/git_old2/ex00/ft_strlen.c
Normal file
21
C_09/git_old2/ex00/ft_strlen.c
Normal file
@@ -0,0 +1,21 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strlen.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gbaconni <gbaconni@42lausanne.ch> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2021/08/22 14:42:47 by gbaconni #+# #+# */
|
||||
/* Updated: 2021/08/22 14:43:21 by gbaconni ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
int ft_strlen(char *str)
|
||||
{
|
||||
char *p_str;
|
||||
|
||||
p_str = str;
|
||||
while (*p_str != '\0')
|
||||
p_str++;
|
||||
return (p_str - str);
|
||||
}
|
||||
20
C_09/git_old2/ex00/ft_swap.c
Normal file
20
C_09/git_old2/ex00/ft_swap.c
Normal file
@@ -0,0 +1,20 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_swap.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gbaconni <gbaconni@42lausanne.ch> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2021/08/22 14:41:30 by gbaconni #+# #+# */
|
||||
/* Updated: 2021/08/22 14:41:35 by gbaconni ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
void ft_swap(int *a, int *b)
|
||||
{
|
||||
int n;
|
||||
|
||||
n = *a;
|
||||
*a = *b;
|
||||
*b = n;
|
||||
}
|
||||
6
C_09/git_old2/ex00/libft_creator.sh
Executable file
6
C_09/git_old2/ex00/libft_creator.sh
Executable file
@@ -0,0 +1,6 @@
|
||||
#!/bin/sh
|
||||
rm -f *.o libft.a
|
||||
gcc -Wall -Wextra -Werror -c *.c
|
||||
ar -cq libft.a *.o
|
||||
#ar -t libft.a
|
||||
#rm -f *.o
|
||||
46
C_09/git_old2/ex00/main.c
Normal file
46
C_09/git_old2/ex00/main.c
Normal file
@@ -0,0 +1,46 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* main.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gbaconni <gbaconni@42lausanne.ch> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2021/08/22 14:55:33 by gbaconni #+# #+# */
|
||||
/* Updated: 2021/08/22 17:19:48 by gbaconni ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.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);
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int a;
|
||||
int b;
|
||||
int r;
|
||||
|
||||
printf("ft_putchar: (expected Z)\n");
|
||||
ft_putchar('Z');
|
||||
printf("\n\n");
|
||||
a = 42;
|
||||
b = 21;
|
||||
printf("ft_swap: (expected a=21 b=42)\n");
|
||||
ft_swap(&a, &b);
|
||||
printf("a=%d b=%d\n\n", a, b);
|
||||
printf("ft_putstr: (expected hello)\n");
|
||||
ft_putstr("hello\n\n");
|
||||
printf("ft_strlen: (expected 5)\n");
|
||||
r = ft_strlen("hello");
|
||||
printf("%d\n\n", r);
|
||||
printf("ft_strcmp: (expected 0)\n");
|
||||
r = ft_strcmp("abc","abc");
|
||||
printf("%d\n\n", r);
|
||||
}
|
||||
14
C_09/git_old2/ex00/main.sh
Executable file
14
C_09/git_old2/ex00/main.sh
Executable file
@@ -0,0 +1,14 @@
|
||||
#!/bin/sh
|
||||
set -e
|
||||
find . -type f -name '*.h' -exec \
|
||||
norminette -R CheckDefine {} \;
|
||||
find . -type f -name '*.c' \! -name 'main.c' -exec \
|
||||
norminette -R CheckForbiddenSourceHeader {} \;
|
||||
echo
|
||||
sh libft_creator.sh
|
||||
rm -f *.o
|
||||
echo
|
||||
echo $(basename $PWD):
|
||||
gcc -Wall -Wextra -Werror -o a.out -L. -lft main.c
|
||||
./a.out "$@"
|
||||
rm -f a.out
|
||||
50
C_09/git_old2/ex01/Makefile
Normal file
50
C_09/git_old2/ex01/Makefile
Normal file
@@ -0,0 +1,50 @@
|
||||
# **************************************************************************** #
|
||||
# #
|
||||
# ::: :::::::: #
|
||||
# Makefile :+: :+: :+: #
|
||||
# +:+ +:+ +:+ #
|
||||
# By: gbaconni <gbaconni@42lausanne.ch> +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# Created: 2021/08/22 17:28:57 by gbaconni #+# #+# #
|
||||
# Updated: 2021/08/22 18:12:53 by gbaconni ### ########.fr #
|
||||
# #
|
||||
# **************************************************************************** #
|
||||
|
||||
#
|
||||
# make fclean
|
||||
# make
|
||||
#
|
||||
|
||||
NAME = libft.a
|
||||
|
||||
SRCDIR = srcs
|
||||
|
||||
SRC = ft_putchar.c \
|
||||
ft_swap.c \
|
||||
ft_putstr.c \
|
||||
ft_strlen.c \
|
||||
ft_strcmp.c
|
||||
|
||||
HDR = ft.h
|
||||
|
||||
INCLUDE = includes
|
||||
|
||||
CC = gcc
|
||||
CFLAGS = -Wall -Wextra -Werror
|
||||
AR = ar
|
||||
ARFLAGS = -cq
|
||||
|
||||
all: $(NAME)
|
||||
|
||||
$(NAME):
|
||||
cd $(SRCDIR) && $(CC) $(CFLAGS) -I $(INCLUDE) -c $(SRC)
|
||||
$(AR) $(ARFLAGS) $(NAME) $(SRCDIR)/*.o
|
||||
|
||||
clean:
|
||||
@/bin/rm -f **/*.o
|
||||
|
||||
fclean: clean
|
||||
@/bin/rm -f $(NAME)
|
||||
|
||||
re: fclean all
|
||||
|
||||
21
C_09/git_old2/ex01/includes/ft.h
Normal file
21
C_09/git_old2/ex01/includes/ft.h
Normal file
@@ -0,0 +1,21 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gbaconni <gbaconni@42lausanne.ch> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2021/08/20 10:17:09 by gbaconni #+# #+# */
|
||||
/* Updated: 2021/08/22 17:40:13 by gbaconni ### ########.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
|
||||
46
C_09/git_old2/ex01/main.c
Normal file
46
C_09/git_old2/ex01/main.c
Normal file
@@ -0,0 +1,46 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* main.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gbaconni <gbaconni@42lausanne.ch> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2021/08/22 14:55:33 by gbaconni #+# #+# */
|
||||
/* Updated: 2021/08/22 17:19:48 by gbaconni ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.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);
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int a;
|
||||
int b;
|
||||
int r;
|
||||
|
||||
printf("ft_putchar: (expected Z)\n");
|
||||
ft_putchar('Z');
|
||||
printf("\n\n");
|
||||
a = 42;
|
||||
b = 21;
|
||||
printf("ft_swap: (expected a=21 b=42)\n");
|
||||
ft_swap(&a, &b);
|
||||
printf("a=%d b=%d\n\n", a, b);
|
||||
printf("ft_putstr: (expected hello)\n");
|
||||
ft_putstr("hello\n\n");
|
||||
printf("ft_strlen: (expected 5)\n");
|
||||
r = ft_strlen("hello");
|
||||
printf("%d\n\n", r);
|
||||
printf("ft_strcmp: (expected 0)\n");
|
||||
r = ft_strcmp("abc","abc");
|
||||
printf("%d\n\n", r);
|
||||
}
|
||||
15
C_09/git_old2/ex01/main.sh
Executable file
15
C_09/git_old2/ex01/main.sh
Executable file
@@ -0,0 +1,15 @@
|
||||
#!/bin/sh
|
||||
set -e
|
||||
find . -type f -name '*.h' -exec \
|
||||
norminette -R CheckDefine {} \;
|
||||
find . -type f -name '*.c' \! -name 'main.c' -exec \
|
||||
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
|
||||
./a.out "$@"
|
||||
rm -f a.out
|
||||
18
C_09/git_old2/ex01/srcs/ft_putchar.c
Normal file
18
C_09/git_old2/ex01/srcs/ft_putchar.c
Normal file
@@ -0,0 +1,18 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_putchar.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gbaconni <gbaconni@42lausanne.ch> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2021/08/22 14:41:08 by gbaconni #+# #+# */
|
||||
/* Updated: 2021/08/22 14:41:17 by gbaconni ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
void ft_putchar(char c)
|
||||
{
|
||||
write(1, &c, 1);
|
||||
}
|
||||
22
C_09/git_old2/ex01/srcs/ft_putstr.c
Normal file
22
C_09/git_old2/ex01/srcs/ft_putstr.c
Normal file
@@ -0,0 +1,22 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_putstr.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gbaconni <gbaconni@42lausanne.ch> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2021/08/22 14:42:02 by gbaconni #+# #+# */
|
||||
/* Updated: 2021/08/22 14:42:04 by gbaconni ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
void ft_putstr(char *str)
|
||||
{
|
||||
char *p_str;
|
||||
|
||||
p_str = str;
|
||||
while (*p_str != '\0')
|
||||
write(1, p_str++, 1);
|
||||
}
|
||||
28
C_09/git_old2/ex01/srcs/ft_strcmp.c
Normal file
28
C_09/git_old2/ex01/srcs/ft_strcmp.c
Normal file
@@ -0,0 +1,28 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strcmp.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gbaconni <gbaconni@42lausanne.ch> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2021/08/22 14:43:35 by gbaconni #+# #+# */
|
||||
/* Updated: 2021/08/22 14:43:44 by gbaconni ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
int ft_strcmp(char *s1, char *s2)
|
||||
{
|
||||
char c1;
|
||||
char c2;
|
||||
|
||||
c1 = '\0';
|
||||
c2 = '\0';
|
||||
while (c1 == c2)
|
||||
{
|
||||
c1 = *s1++;
|
||||
c2 = *s2++;
|
||||
if (c1 == '\0')
|
||||
break ;
|
||||
}
|
||||
return (c1 - c2);
|
||||
}
|
||||
21
C_09/git_old2/ex01/srcs/ft_strlen.c
Normal file
21
C_09/git_old2/ex01/srcs/ft_strlen.c
Normal file
@@ -0,0 +1,21 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strlen.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gbaconni <gbaconni@42lausanne.ch> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2021/08/22 14:42:47 by gbaconni #+# #+# */
|
||||
/* Updated: 2021/08/22 14:43:21 by gbaconni ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
int ft_strlen(char *str)
|
||||
{
|
||||
char *p_str;
|
||||
|
||||
p_str = str;
|
||||
while (*p_str != '\0')
|
||||
p_str++;
|
||||
return (p_str - str);
|
||||
}
|
||||
20
C_09/git_old2/ex01/srcs/ft_swap.c
Normal file
20
C_09/git_old2/ex01/srcs/ft_swap.c
Normal file
@@ -0,0 +1,20 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_swap.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gbaconni <gbaconni@42lausanne.ch> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2021/08/22 14:41:30 by gbaconni #+# #+# */
|
||||
/* Updated: 2021/08/22 14:41:35 by gbaconni ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
void ft_swap(int *a, int *b)
|
||||
{
|
||||
int n;
|
||||
|
||||
n = *a;
|
||||
*a = *b;
|
||||
*b = n;
|
||||
}
|
||||
99
C_09/git_old2/ex02/ft_split.c
Normal file
99
C_09/git_old2/ex02/ft_split.c
Normal file
@@ -0,0 +1,99 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_split.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gbaconni <gbaconni@42lausanne.ch> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2021/08/22 18:14:04 by gbaconni #+# #+# */
|
||||
/* Updated: 2021/08/24 13:00:34 by gbaconni ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
static char *ft_strncpy(char *dest, char *src, unsigned int n)
|
||||
{
|
||||
unsigned int i;
|
||||
|
||||
i = 0;
|
||||
while (i < n && src[i] != '\0')
|
||||
{
|
||||
dest[i] = src[i];
|
||||
i++;
|
||||
}
|
||||
while (i < n)
|
||||
{
|
||||
dest[i] = '\0';
|
||||
i++;
|
||||
}
|
||||
return (dest);
|
||||
}
|
||||
|
||||
static int ft_is_charset(char c, char *charset)
|
||||
{
|
||||
char *p_charset;
|
||||
int r;
|
||||
|
||||
r = 0;
|
||||
p_charset = charset;
|
||||
while (*p_charset != '\0')
|
||||
r |= (*p_charset++ == c);
|
||||
return (r);
|
||||
}
|
||||
|
||||
static int ft_split_len(char *str, char *charset)
|
||||
{
|
||||
char *p_str;
|
||||
int size;
|
||||
|
||||
size = 2;
|
||||
p_str = str;
|
||||
while (*p_str != '\0')
|
||||
{
|
||||
if (ft_is_charset(*p_str++, charset) == 1)
|
||||
size++;
|
||||
}
|
||||
return (size);
|
||||
}
|
||||
|
||||
char *ft_copy(char *str, int size)
|
||||
{
|
||||
char *result;
|
||||
|
||||
result = (char *) malloc((size + 1) * sizeof(char));
|
||||
if (size > 0)
|
||||
ft_strncpy(result, str, size);
|
||||
else
|
||||
result[0] = '\0';
|
||||
return (result);
|
||||
}
|
||||
|
||||
char **ft_split(char *str, char *charset)
|
||||
{
|
||||
char **strs;
|
||||
char *start;
|
||||
int size;
|
||||
int i;
|
||||
|
||||
size = ft_split_len(str, charset);
|
||||
strs = malloc((size) * sizeof(strs));
|
||||
start = str;
|
||||
i = 0;
|
||||
while (1)
|
||||
{
|
||||
if (ft_is_charset(*str, charset) == 1 || *str == '\0')
|
||||
{
|
||||
size = str - start;
|
||||
if (size > 0)
|
||||
strs[i++] = ft_copy(start, size);
|
||||
start = str + 1;
|
||||
if (*str == '\0')
|
||||
break ;
|
||||
}
|
||||
str++;
|
||||
}
|
||||
strs[i] = ft_copy(str, 0);
|
||||
return (strs);
|
||||
}
|
||||
40
C_09/git_old2/ex02/main.c
Normal file
40
C_09/git_old2/ex02/main.c
Normal file
@@ -0,0 +1,40 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* main.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gbaconni <gbaconni@42lausanne.ch> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2021/08/18 10:50:59 by gbaconni #+# #+# */
|
||||
/* Updated: 2021/08/24 11:56:21 by gbaconni ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
char **ft_split(char *str, char *charset);
|
||||
|
||||
int main(void)
|
||||
{
|
||||
char str[32];
|
||||
char charset[32];
|
||||
char **strs;
|
||||
int i;
|
||||
|
||||
printf("Input String [Max 32]: ");
|
||||
scanf("%s", str);
|
||||
printf("Input Charset [Max 32]: ");
|
||||
scanf("%s", charset);
|
||||
strs = ft_split(str, charset);
|
||||
printf("str=%s charset=%s (ft_split)\n", str, charset);
|
||||
i = 0;
|
||||
while (strs[i][0] != '\0')
|
||||
{
|
||||
printf("strs[%d] = %s\n", i, strs[i]);
|
||||
i++;
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
9
C_09/git_old2/ex02/main.sh
Executable file
9
C_09/git_old2/ex02/main.sh
Executable file
@@ -0,0 +1,9 @@
|
||||
#!/bin/sh
|
||||
set -e
|
||||
rm -f a.out
|
||||
#norminette -R CheckForbiddenSourceHeader ft_*.c
|
||||
norminette -R CheckForbiddenSourceHeader
|
||||
gcc -Wall -Wextra -Werror -o a.out *.c
|
||||
echo $(basename $PWD):
|
||||
./a.out
|
||||
rm -f a.out
|
||||
Reference in New Issue
Block a user