Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
laseine committed Sep 17, 2018
1 parent 01f8d55 commit 8c06034
Show file tree
Hide file tree
Showing 33 changed files with 963 additions and 0 deletions.
35 changes: 35 additions & 0 deletions with_mains_day10/ex00/Makefile
@@ -0,0 +1,35 @@
##
## lahsen El bouhali
##

NAME = libft.a
INC = ./includes/
SRC = ./srcs/
SRCS = $(SRC)ft_putchar.c $(SRC)ft_putstr.c \
$(SRC)ft_strcmp.c $(SRC)ft_strlen.c \
$(SRC)ft_swap.c
OBJ = ft_putchar.o ft_putstr.o ft_strcmp.o ft_strlen.o ft_swap.o
RMOBJ = @-rm -f ./*.o
RMLIB = @-rm -f ./libft.a
AR = @ar -rv
CC = gcc
CFLAG = -Wall -Werror -Wextra
OPTION = -c -I$(INC)*.h

all: $(NAME)

$(NAME):
$(CC) $(CFLAG) $(OPTION) $(SRCS)
ar rc $(NAME) $(OBJ)

clean:
$(RMOBJ)

fclean:
$(RMOBJ)
$(RMLIB)

re:
$(RMOBJ)
$(RMLIB)
make
22 changes: 22 additions & 0 deletions with_mains_day10/ex00/includes/libft.h
@@ -0,0 +1,22 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* libft.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rfseffa <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/09/10 17:51:04 by rfseffa #+# #+# */
/* Updated: 2018/09/11 12:59:16 by rfseffa ### ########.fr */
/* */
/* ************************************************************************** */

#ifndef LIBFT_H
# define LIBFT_H

void ft_putchar(char c);
void ft_putstr(char *str);
int ft_strcmp(char *s1, char *s2);
int ft_strlen(char *str);
void ft_swap(int *a, int *b);

#endif
18 changes: 18 additions & 0 deletions with_mains_day10/ex00/srcs/ft_putchar.c
@@ -0,0 +1,18 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putchar.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rfseffa <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/09/10 17:51:04 by rfseffa #+# #+# */
/* Updated: 2018/09/11 12:59:16 by rfseffa ### ########.fr */
/* */
/* ************************************************************************** */

#include <unistd.h>

void ft_putchar(char c)
{
write(1, &c, 1);
}
22 changes: 22 additions & 0 deletions with_mains_day10/ex00/srcs/ft_putstr.c
@@ -0,0 +1,22 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putstr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rfseffa <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/09/10 17:51:04 by rfseffa #+# #+# */
/* Updated: 2018/09/11 12:59:16 by rfseffa ### ########.fr */
/* */
/* ************************************************************************** */

void ft_putchar(char c);

void ft_putstr(char *str)
{
while (*str)
{
ft_putchar(*str);
str++;
}
}
26 changes: 26 additions & 0 deletions with_mains_day10/ex00/srcs/ft_strcmp.c
@@ -0,0 +1,26 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strcmp.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rfseffa <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/09/10 17:51:04 by rfseffa #+# #+# */
/* Updated: 2018/09/11 12:59:16 by rfseffa ### ########.fr */
/* */
/* ************************************************************************** */

int ft_strcmp(char *s1, char *s2)
{
int i;

i = 0;
while ((s1[i] != '\0') && (s2[i] != '\0'))
{
if (s1[i] == s2[i])
i++;
else
break ;
}
return (s1[i] - s2[i]);
}
24 changes: 24 additions & 0 deletions with_mains_day10/ex00/srcs/ft_strlen.c
@@ -0,0 +1,24 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strlen.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rfseffa <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/09/10 17:51:04 by rfseffa #+# #+# */
/* Updated: 2018/09/11 12:59:16 by rfseffa ### ########.fr */
/* */
/* ************************************************************************** */

int ft_strlen(char *str)
{
int len;

len = 0;
while (*str != '\0')
{
str++;
len++;
}
return (len);
}
21 changes: 21 additions & 0 deletions with_mains_day10/ex00/srcs/ft_swap.c
@@ -0,0 +1,21 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_swap.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rfseffa <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/09/10 17:51:04 by rfseffa #+# #+# */
/* Updated: 2018/09/11 12:59:16 by rfseffa ### ########.fr */
/* */
/* ************************************************************************** */

void ft_swap(int *a, int *b)
{
int *c;

c = 0;
*c = *a;
*a = *b;
*b = *c;
}
Binary file added with_mains_day10/ex01/a.out
Binary file not shown.
23 changes: 23 additions & 0 deletions with_mains_day10/ex01/ft_foreach.c
@@ -0,0 +1,23 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_foreach.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rfseffa <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/09/12 00:13:04 by rfseffa #+# #+# */
/* Updated: 2018/09/12 04:59:16 by rfseffa ### ########.fr */
/* */
/* ************************************************************************** */

void ft_foreach(int *tab, int length, void (*f)(int))
{
int i;

i = 0;
while (i < length)
{
f(tab[i]);
i++;
}
}
76 changes: 76 additions & 0 deletions with_mains_day10/ex01/main.c
@@ -0,0 +1,76 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rfseffa <marvin@1337.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/09/12 04:23:04 by rfseffa #+# #+# */
/* Updated: 2018/09/12 08:59:16 by rfseffa ### ########.fr */
/* */
/* ************************************************************************** */

#include <stdio.h>
#include <unistd.h>

void ft_putchar(char c)
{
write(1, &c, 1);
}

void ft_putnbr(int nbr)
{
if (nbr < 0)
{
ft_putchar('-');
nbr = -nbr;
}
if (nbr >= 10)
{
ft_putnbr(nbr / 10);
ft_putchar((nbr % 10) + '0');
}
else
ft_putchar(nbr + '0');
}

void ft_putnbr_clean(int nbr)
{
ft_putnbr(nbr);
ft_putchar('\n');
}

void mafonction_f(int i)
{
printf("cette fonction affiche les élèments du tableau : %d\n", i);
}

void ft_foreach(int *tab, int lenght, void (*f)(int));

/* déclaration du pointeur sur fonction f = mafonction_f
** Initialisation de la fonction ft_foreach(tab, 5, (f))
** Appel de la fonction ft_foreach(tab, 5, (f))
*/

int main(void)
{
int i;
int tab[5] = {0, 1337, 42, +1, -1};
void (*f)(int);

printf("tableau d'entiers\n");
i = 0;
while (i < 5)
{
printf("tab[%d]:%d\n", i, tab[i]);
i++;
}
printf("----------\n");
f = mafonction_f;
ft_foreach(tab, 5, (f));
i = 0;
printf("----------\n");
ft_foreach(tab, 5, &ft_putnbr_clean);
ft_putchar('\n');
return (0);
}
Binary file added with_mains_day10/ex02/a.out
Binary file not shown.
28 changes: 28 additions & 0 deletions with_mains_day10/ex02/ft_map.c
@@ -0,0 +1,28 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_map.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rfseffa <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/09/13 10:13:04 by rfseffa #+# #+# */
/* Updated: 2018/09/13 18:59:16 by rfseffa ### ########.fr */
/* */
/* ************************************************************************** */

#include <stdlib.h>

int *ft_map(int *tab, int length, int (*g)(int))
{
int *tmp;
int i;

i = 0;
tmp = (int*)malloc(sizeof(int) * length);
while (i < length)
{
tmp[i] = g(tab[i]);
i++;
}
return (tmp);
}
39 changes: 39 additions & 0 deletions with_mains_day10/ex02/main.c
@@ -0,0 +1,39 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rfseffa <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/09/13 10:13:04 by rfseffa #+# #+# */
/* Updated: 2018/09/13 18:59:16 by rfseffa ### ########.fr */
/* */
/* ************************************************************************** */

#include <stdio.h>
//#include <stdlib.h>

int mafonction_g(int i)
{
return (2 * i);
}

int *ft_map(int *tab, int length, int (*g)(int));

int main(void)
{
int tab[4] = {1,2,3,4};
int *dTab;
int k;
int (*g)(int); /*déclaration du pointeur sur fonction pour g*/

g = mafonction_g; /*Initialisation pour g*/
dTab = ft_map(tab, 4, (*g)); /*Appel g*/
k = 0;
while (k < 4)
{
printf("tab[%d] = %d, Application de la fonction f(x) = 2 * x ==> tab[%d] = %d\n", k, tab[k], k, dTab[k]);
k++;
}
return(0);
}
Binary file added with_mains_day10/ex03/a.out
Binary file not shown.
25 changes: 25 additions & 0 deletions with_mains_day10/ex03/ft_any.c
@@ -0,0 +1,25 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_any.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rfseffa <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/09/13 10:13:04 by rfseffa #+# #+# */
/* Updated: 2018/09/13 18:59:16 by rfseffa ### ########.fr */
/* */
/* ************************************************************************** */

int ft_any(char **tab, int (*f)(char*))
{
int i;

i = 0;
while (tab[i] != '\0')
{
if (f(tab[i]) == 1)
return (1);
i++;
}
return (0);
}

0 comments on commit 8c06034

Please sign in to comment.