Skip to content
This repository has been archived by the owner on Nov 30, 2024. It is now read-only.

Commit

Permalink
reorganizing repositories
Browse files Browse the repository at this point in the history
  • Loading branch information
mcombeau committed Jan 22, 2022
0 parents commit 1a0b9ac
Show file tree
Hide file tree
Showing 50 changed files with 3,449 additions and 0 deletions.
85 changes: 85 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
# **************************************************************************** #
# #
# ::: :::::::: #
# Makefile :+: :+: :+: #
# +:+ +:+ +:+ #
# By: mcombeau <marvin@42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2021/11/22 13:48:30 by mcombeau #+# #+# #
# Updated: 2021/12/02 13:26:19 by mcombeau ### ########.fr #
# #
# **************************************************************************** #

NAME = libft.a
CC = gcc
CFLAGS = -Wall -Werror -Wextra -g3
AR = ar rcs
SRC = ft_isalpha \
ft_isdigit \
ft_isalnum \
ft_isascii \
ft_isprint \
ft_strlen \
ft_memset \
ft_bzero \
ft_memcpy \
ft_memmove \
ft_strlcpy \
ft_strlcat \
ft_toupper \
ft_tolower \
ft_strchr \
ft_strrchr \
ft_strncmp \
ft_memchr \
ft_memcmp \
ft_strnstr \
ft_atoi \
ft_calloc \
ft_strdup \
ft_substr \
ft_strjoin \
ft_strtrim \
ft_split \
ft_itoa \
ft_strmapi \
ft_striteri \
ft_putchar_fd \
ft_putstr_fd \
ft_putendl_fd \
ft_putnbr_fd
BONUS_SRC = ft_lstnew \
ft_lstadd_front \
ft_lstsize \
ft_lstlast \
ft_lstadd_back \
ft_lstdelone \
ft_lstclear \
ft_lstiter \
ft_lstmap

SRCS = $(addsuffix .c, $(SRC))
OBJS = $(addsuffix .o, $(SRC))
BONUS_SRCS = $(addsuffix .c, $(BONUS_SRC))
BONUS_OBJS = $(addsuffix .o, $(BONUS_SRC))

.c.o: $(SRCS) $(BONUS_SRCS)
$(CC) $(CFLAGS) -c -o $@ $<

$(NAME): $(OBJS)
$(AR) $@ $^

bonus: $(OBJS) $(BONUS_OBJS)
$(AR) $(NAME) $^

all: $(NAME)

clean:
rm -f *.o

fclean: clean
rm -f $(NAME)

re: clean all

.PHONY: all clean fclean re bonus
79 changes: 79 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# libft
42 school's first project, libft, is about learning how the standard functions of C programming work, by coding them from scratch and creating our very own library.

Libft is a very important project, since this library will be used in future 42 school assignments. If you are a 42 student, I highly recommend you go through the trial and error process of writing your own code and testing it yourself, rather than copy-pasting code you only half-understand. If you've succeeded your piscine, there is no reason you couldn't figure this project out for yourself! Be patient and thorough.

## Status
2022-01-18: Finished.

[![jaeskim's 42Project Score](https://badge42.herokuapp.com/api/project/mcombeau/Libft)](https://github.com/JaeSeoKim/badge42)

## Usage
``make`` to compile mandatory functions.

``make bonus`` to compile with bonus functions.

## Included Functions

### Mandatory Functions
The mandatory functions of libft are either functions from the standard C library or other useful functions. They are mostly useful for character, string and memory manipulation. These 34 mandatory functions must be done correctly to get a 100% grade.

Functions to check and manipulate characters:
- ft_isalpha
- ft_isdigit
- ft_isalnum
- ft_isascii
- ft_isprint
- ft_toupper
- ft_tolower

Functions to manipulate strings:
- ft_strlen
- ft_strlcpy
- ft_strlcat
- ft_strchr
- ft_strrchr
- ft_strncmp
- ft_strnstr
- ft_substr
- ft_strjoin
- ft_strtrim
- ft_split
- ft_strmapi
- ft_striteri

Functions to manipulate memory:
- ft_calloc
- ft_memset
- ft_bzero
- ft_memcpy
- ft_memmove
- ft_memchr
- ft_memcmp
- ft_strdup

Functions for numbers:
- ft_atoi
- ft_itoa

Functions to write to a file descriptor
- ft_putchar_fd
- ft_putstr_fd
- ft_putendl_fd
- ft_putnbr_fd

### Bonus Functions
The bonus functions of libft deal with list manipulation. This part is worth an extra 25% to the final grade.
- ft_lstnew
- ft_lstadd_front
- ft_lstsize
- ft_lstlast
- ft_lstadd_back
- ft_lstdelone
- ft_lstclear
- ft_lstiter
- ft_lstmap


---
Made by mcombeau: mcombeau@student.42.fr | LinkedIn: [mcombeau](https://www.linkedin.com/in/mia-combeau-86653420b/) | Website: [codequoi.com](https://www.codequoi.com)
49 changes: 49 additions & 0 deletions ft_atoi.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_atoi.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mcombeau <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/11/24 18:06:58 by mcombeau #+# #+# */
/* Updated: 2021/12/02 16:48:58 by mcombeau ### ########.fr */
/* */
/* ************************************************************************** */

#include "libft.h"

/*
DESCRIPTION :
The function ft_atoi converts a string into an int.
RETURN VALUE :
The converted int.
*/

int ft_atoi(const char *str)
{
int num;
int isneg;
int i;

num = 0;
isneg = 1;
i = 0;
while (str[i] && (str[i] == ' ' || str[i] == '\t'
|| str[i] == '\n' || str[i] == '\r'
|| str[i] == '\v' || str[i] == '\f'))
i++;
if (str[i] == '+')
i++;
else if (str[i] == '-')
{
isneg *= -1;
i++;
}
while (ft_isdigit(str[i]))
{
num = (num * 10) + (str[i] - '0');
i++;
}
return (num * isneg);
}
35 changes: 35 additions & 0 deletions ft_bzero.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_bzero.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mcombeau <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/11/23 14:22:49 by mcombeau #+# #+# */
/* Updated: 2021/12/02 14:21:37 by mcombeau ### ########.fr */
/* */
/* ************************************************************************** */

#include "libft.h"

/*
DESCRIPTION :
The function ft_bzero erases data in the n bytes of memory starting
at location s by writing '\0's.
RETURN VALUE :
None.
*/

void ft_bzero(void *s, size_t n)
{
unsigned char *p;

p = (unsigned char *)s;
while (n != 0)
{
*p = '\0';
p++;
n--;
}
}
33 changes: 33 additions & 0 deletions ft_calloc.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_calloc.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mcombeau <mcombeau@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/11/26 15:28:22 by mcombeau #+# #+# */
/* Updated: 2021/12/02 16:49:19 by mcombeau ### ########.fr */
/* */
/* ************************************************************************** */

#include "libft.h"

/*
DESCRIPTION :
The function ft_calloc allocates memory for an array of count elements
of size bytes each and sets the memory to zero.
RETURN VALUE :
The pointer to the allocated memory. NULL if the memory allocation fails.
*/

void *ft_calloc(size_t count, size_t size)
{
void *r;

r = malloc(count * size);
if (!r)
return (NULL);
ft_bzero(r, size * count);
return (r);
}
28 changes: 28 additions & 0 deletions ft_isalnum.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_isalnum.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mcombeau <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/11/22 13:52:40 by mcombeau #+# #+# */
/* Updated: 2021/12/02 16:49:56 by mcombeau ### ########.fr */
/* */
/* ************************************************************************** */

#include "libft.h"

/*
DESCRIPTION :
The function ft_isalnum checks whether the value of c is alphanumeric.
RETURN VALUE :
Non-zero if c is alphanumeric, zero if not.
*/

int ft_isalnum(int c)
{
if (ft_isalpha(c) || ft_isdigit(c))
return (c);
return (0);
}
26 changes: 26 additions & 0 deletions ft_isalpha.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_isalpha.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mcombeau <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/11/22 13:50:28 by mcombeau #+# #+# */
/* Updated: 2021/12/02 14:36:38 by mcombeau ### ########.fr */
/* */
/* ************************************************************************** */

/*
DESCRIPTION :
The function ft_isalpha checks whether c is alphabetic or not.
RETURN VALUE :
Non-zero if c is alphabetic, zero if not.
*/

int ft_isalpha(int c)
{
if ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z'))
return (c);
return (0);
}
28 changes: 28 additions & 0 deletions ft_isascii.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_isascii.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mcombeau <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/11/22 13:48:51 by mcombeau #+# #+# */
/* Updated: 2021/12/02 14:38:16 by mcombeau ### ########.fr */
/* */
/* ************************************************************************** */

/*
DESCRIPTION :
The function ft_isascii checks whether c is an ascii character or not.
RESULT VALUE :
Non-zero if c is ascii, zero if not.
*/

int ft_isascii(int c)
{
if (c == 0)
return (1);
if (c > 0 && c <= 127)
return (c);
return (0);
}
26 changes: 26 additions & 0 deletions ft_isdigit.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_isdigit.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mcombeau <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/11/22 13:53:06 by mcombeau #+# #+# */
/* Updated: 2021/12/02 14:40:52 by mcombeau ### ########.fr */
/* */
/* ************************************************************************** */

/*
DESCRIPTION :
The function ft_isdigit checks whether c is a digit character or not.
RETURN VALUE:
Non-zero if c is a digit, zero if not.
*/

int ft_isdigit(int c)
{
if (c >= '0' && c <= '9')
return (c);
return (0);
}
Loading

0 comments on commit 1a0b9ac

Please sign in to comment.