0
0
This commit is contained in:
Guy Baconniere
2021-08-22 18:10:08 +02:00
parent 2e3daba75a
commit 886ab5481c
44 changed files with 774 additions and 11 deletions

50
C_09/git/ex01/Makefile Normal file
View File

@@ -0,0 +1,50 @@
# **************************************************************************** #
# #
# ::: :::::::: #
# Makefile :+: :+: :+: #
# +:+ +:+ +:+ #
# By: gbaconni <gbaconni@42lausanne.ch> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2021/08/22 17:28:57 by gbaconni #+# #+# #
# Updated: 2021/08/22 17:43:24 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

View 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/ex01/main.c Normal file
View 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/ex01/main.sh Executable file
View 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

View 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);
}

View 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);
}

View 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);
}

View 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);
}

View 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;
}