Skip to content

Commit b2c743b

Browse files
committed
chore - moved all files to root folder for uploading
1 parent bcd4ef2 commit b2c743b

37 files changed

+1602
-0
lines changed

Makefile

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# **************************************************************************** #
2+
# #
3+
# ::: :::::::: #
4+
# Makefile :+: :+: :+: #
5+
# +:+ +:+ +:+ #
6+
# By: mmaurer <[email protected]> +#+ +:+ +#+ #
7+
# +#+#+#+#+#+ +#+ #
8+
# Created: 2021/08/13 14:27:16 by mmaurer #+# #+# #
9+
# Updated: 2021/09/09 14:12:36 by mmaurer ### ########.fr #
10+
# #
11+
# **************************************************************************** #
12+
13+
SRC = ft_memset.c ft_bzero.c ft_memcpy.c ft_memccpy.c ft_isalpha.c \
14+
ft_isdigit.c ft_isalnum.c ft_isascii.c ft_isprint.c ft_toupper.c \
15+
ft_tolower.c ft_atoi.c ft_strlen.c ft_strlcpy.c ft_memmove.c ft_strlcat.c \
16+
ft_strchr.c ft_strrchr.c ft_strncmp.c ft_strnstr.c ft_memchr.c \
17+
ft_memcmp.c ft_strdup.c ft_calloc.c ft_substr.c ft_strtrim.c ft_strjoin.c \
18+
ft_putchar_fd.c ft_putstr_fd.c ft_putendl_fd.c ft_putnbr_fd.c \
19+
ft_striteri.c ft_strmapi.c ft_itoa.c ft_split.c
20+
OBJS = $(SRC) #${SRC:.c=.o}
21+
HEADERS = libft.h
22+
NAME = libft.a
23+
CC = gcc
24+
FLAGS = -Wall -Wextra -Werror
25+
26+
all: $(NAME)
27+
28+
$(NAME): clean
29+
@$(CC) -c $(FLAGS) $(OBJS)
30+
@ar rc $(NAME) *.o
31+
@ranlib $(NAME)
32+
@rm -f *.o *.gch
33+
# norminette $(SRC)
34+
35+
clean:
36+
@/bin/rm -f *.o
37+
38+
fclean: clean
39+
@/bin/rm -f $(NAME)
40+
41+
re: fclean all
42+
43+
test: all
44+
@$(CC) ../tests/test_ft_itoa.c -L. -lft -o ../tests/a.out
45+
@../tests/a.out
46+
47+
.PHONY: all clean fclean re test

ft_atoi.c

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/* ************************************************************************** */
2+
/* */
3+
/* ::: :::::::: */
4+
/* ft_atoi.c :+: :+: :+: */
5+
/* +:+ +:+ +:+ */
6+
/* By: mmaurer <[email protected]> +#+ +:+ +#+ */
7+
/* +#+#+#+#+#+ +#+ */
8+
/* Created: 2021/08/24 17:08:33 by mmaurer #+# #+# */
9+
/* Updated: 2021/09/07 21:31:25 by mmaurer ### ########.fr */
10+
/* */
11+
/* ************************************************************************** */
12+
13+
#include "libft.h"
14+
15+
/*
16+
* The atoi() function converts the initial portion of the string pointed to by
17+
* nptr to int.
18+
* Gracefull handles non-printable characters at the beginning of the string,
19+
* then flips sign if required and then converts character to digit until the
20+
* end of the string is reached using this algorithm result * 10 + (str[i] - '0')
21+
* and stores in result.
22+
1. We start by initializing i to 0 and result to 0.
23+
2. We then loop through the string until we reach the end of the string or a
24+
non-digit character.
25+
3. If we encounter a ‘-‘, we set sign to -1.
26+
4. If we encounter a ‘+’, we set sign to 1.
27+
*/
28+
int ft_atoi(const char *str)
29+
{
30+
size_t i;
31+
size_t result;
32+
int sign;
33+
34+
i = 0;
35+
result = 0;
36+
sign = 1;
37+
while ((str[i] == '\n' || str[i] == '\t' || str[i] == ' ')
38+
|| str[i] == '\v' || str[i] == '\f' || str[i] == '\r')
39+
i++;
40+
if (str[i] == '-')
41+
sign = -1;
42+
if (str[i] == '-' || str[i] == '+')
43+
i++;
44+
while (str[i] >= '0' && str[i] <= '9')
45+
{
46+
result = result * 10 + (str[i] - '0');
47+
i++;
48+
}
49+
return (result * sign);
50+
}

ft_bzero.c

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/* ************************************************************************** */
2+
/* */
3+
/* ::: :::::::: */
4+
/* ft_bzero.c :+: :+: :+: */
5+
/* +:+ +:+ +:+ */
6+
/* By: mmaurer <[email protected]> +#+ +:+ +#+ */
7+
/* +#+#+#+#+#+ +#+ */
8+
/* Created: 2021/08/18 12:31:47 by mmaurer #+# #+# */
9+
/* Updated: 2021/09/07 21:42:50 by mmaurer ### ########.fr */
10+
/* */
11+
/* ************************************************************************** */
12+
13+
#include "libft.h"
14+
15+
/* The bzero() function erases the data in the n bytes of the memory
16+
* starting at the location pointed to by s, by writing zeros (bytes containing
17+
* '\0') to that area.
18+
1. The ft_bzero() function takes two arguments: a void pointer to the memory
19+
area to be modified and the size of the memory area.
20+
2. The ft_bzero() function first stores the address of the memory area in a
21+
char pointer.
22+
3. The while loop runs as long as n is greater than 0.
23+
4. The *cptr pointer is incremented by 1 and n is decremented by 1.
24+
5. The *cptr pointer is set to '\0' and the memory location pointed to by cptr
25+
is set to '\0'.
26+
6. The ft_bzero() function returns nothing.
27+
*/
28+
void ft_bzero(void *s, size_t n)
29+
{
30+
char *cptr;
31+
32+
cptr = s;
33+
while (n)
34+
{
35+
*cptr = '\0';
36+
cptr++;
37+
n--;
38+
}
39+
}

ft_calloc.c

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/* ************************************************************************** */
2+
/* */
3+
/* ::: :::::::: */
4+
/* ft_calloc.c :+: :+: :+: */
5+
/* +:+ +:+ +:+ */
6+
/* By: mmaurer <[email protected]> +#+ +:+ +#+ */
7+
/* +#+#+#+#+#+ +#+ */
8+
/* Created: 2021/08/29 21:54:41 by mmaurer #+# #+# */
9+
/* Updated: 2021/09/07 21:34:42 by mmaurer ### ########.fr */
10+
/* */
11+
/* ************************************************************************** */
12+
13+
#include "libft.h"
14+
15+
/*
16+
* The malloc() function allocates size bytes and returns a pointer to the
17+
* allocated memory. The memory is not initialized. If size is 0, then malloc()
18+
* returns either NULL, or a unique pointer value that can later be successfully
19+
* passed to free().
20+
* The free() function frees the memory space pointed to by ptr, which must have
21+
* been returned by a previous call to malloc(), calloc(), or realloc().
22+
* Otherwise, or if free(ptr) has already been called before, undefined
23+
* behavior occurs. If ptr is NULL, no operation is performed.
24+
* The calloc()
25+
* function allocates memory for an array of nmemb elements of size bytes each
26+
* and returns a pointer to the allocated memory. The memory is set to zero.
27+
* If nmemb or size is 0, then calloc() returns either NULL, or a unique pointer
28+
* value that can later be successfully passed to free(). If the multiplication
29+
* of nmemb and size would result in integer overflow, then calloc() returns an
30+
* error. By contrast, an integer overflow would not be detected in the
31+
* following call to malloc(), with the result that an incorrectly sized block
32+
* of memory would be allocated: malloc(nmemb * size);
33+
* Return:
34+
* The malloc() and calloc() functions return a pointer to the allocated
35+
* memory, which is suitably aligned for any built-in type. On error, these
36+
* functions return NULL. NULL may also be returned by a successful call to
37+
* malloc() with a size of zero, or by a successful call to calloc() with nmemb
38+
* or size equal to zero.
39+
*/
40+
void *ft_calloc(size_t nmemb, size_t size)
41+
{
42+
void *p;
43+
44+
p = malloc(nmemb * size);
45+
if (!p)
46+
return (NULL);
47+
ft_bzero(p, nmemb * size);
48+
return (p);
49+
}

ft_isalnum.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/* ************************************************************************** */
2+
/* */
3+
/* ::: :::::::: */
4+
/* ft_isalnum.c :+: :+: :+: */
5+
/* +:+ +:+ +:+ */
6+
/* By: mmaurer <[email protected]> +#+ +:+ +#+ */
7+
/* +#+#+#+#+#+ +#+ */
8+
/* Created: 2021/08/24 15:17:31 by mmaurer #+# #+# */
9+
/* Updated: 2021/09/07 21:35:59 by mmaurer ### ########.fr */
10+
/* */
11+
/* ************************************************************************** */
12+
13+
#include "libft.h"
14+
15+
/*
16+
* checks for an alphanumeric character; it is equivalent to
17+
* (isalpha(c) || isdigit(c))
18+
1. The ft_isalnum function checks if the character is an alphabet or a digit.
19+
2. If it is, it returns 1, otherwise 0.
20+
3. The ft_isalpha function checks if the character is an alphabet.
21+
*/
22+
int ft_isalnum(int c)
23+
{
24+
if (ft_isalpha(c) || ft_isdigit(c))
25+
return (1);
26+
return (0);
27+
}

ft_isalpha.c

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/* ************************************************************************** */
2+
/* */
3+
/* ::: :::::::: */
4+
/* ft_isalpha.c :+: :+: :+: */
5+
/* +:+ +:+ +:+ */
6+
/* By: mmaurer <[email protected]> +#+ +:+ +#+ */
7+
/* +#+#+#+#+#+ +#+ */
8+
/* Created: 2021/08/23 19:27:10 by mmaurer #+# #+# */
9+
/* Updated: 2021/09/07 21:43:56 by mmaurer ### ########.fr */
10+
/* */
11+
/* ************************************************************************** */
12+
13+
#include "libft.h"
14+
15+
/*
16+
checks for an alphabetic character; in the standard "C" locale, it is
17+
equivalent to (isupper(c) || islower(c)). In some locales, there may be
18+
additional characters for which isalpha() is true—letters which are neither
19+
uppercase nor lowercase.
20+
1. The ft_isalpha() function takes a character as an argument and returns 1 if
21+
it is an alphabet, 0 otherwise.
22+
2. The while loop checks if the character is either a lowercase or an uppercase
23+
alphabet.
24+
3. If the character is either a lowercase or an uppercase alphabet, the
25+
function returns 1.
26+
4. If the character is not an alphabet, the function returns 0.
27+
*/
28+
int ft_isalpha(int c)
29+
{
30+
while ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'))
31+
return (1);
32+
return (0);
33+
}

ft_isascii.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/* ************************************************************************** */
2+
/* */
3+
/* ::: :::::::: */
4+
/* ft_isascii.c :+: :+: :+: */
5+
/* +:+ +:+ +:+ */
6+
/* By: mmaurer <[email protected]> +#+ +:+ +#+ */
7+
/* +#+#+#+#+#+ +#+ */
8+
/* Created: 2021/08/24 15:25:15 by mmaurer #+# #+# */
9+
/* Updated: 2021/09/07 21:37:56 by mmaurer ### ########.fr */
10+
/* */
11+
/* ************************************************************************** */
12+
13+
#include "libft.h"
14+
15+
/*
16+
* checks whether c is a 7-bit unsigned char value that fits into the ASCII
17+
* character set.
18+
*/
19+
int ft_isascii(int c)
20+
{
21+
if ((c >= 0) && (c <= 127))
22+
return (1);
23+
return (0);
24+
}

ft_isdigit.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/* ************************************************************************** */
2+
/* */
3+
/* ::: :::::::: */
4+
/* ft_isdigit.c :+: :+: :+: */
5+
/* +:+ +:+ +:+ */
6+
/* By: mmaurer <[email protected]> +#+ +:+ +#+ */
7+
/* +#+#+#+#+#+ +#+ */
8+
/* Created: 2021/08/24 14:22:40 by mmaurer #+# #+# */
9+
/* Updated: 2021/09/01 23:24:18 by mmaurer ### ########.fr */
10+
/* */
11+
/* ************************************************************************** */
12+
13+
#include "libft.h"
14+
15+
/*
16+
* checks for a digit (0 through 9).
17+
*/
18+
int ft_isdigit(int c)
19+
{
20+
if (c >= '0' && c <= '9')
21+
return (1);
22+
return (0);
23+
}

ft_isprint.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/* ************************************************************************** */
2+
/* */
3+
/* ::: :::::::: */
4+
/* ft_isprint.c :+: :+: :+: */
5+
/* +:+ +:+ +:+ */
6+
/* By: mmaurer <[email protected]> +#+ +:+ +#+ */
7+
/* +#+#+#+#+#+ +#+ */
8+
/* Created: 2021/08/24 15:43:09 by mmaurer #+# #+# */
9+
/* Updated: 2021/09/01 23:24:22 by mmaurer ### ########.fr */
10+
/* */
11+
/* ************************************************************************** */
12+
13+
#include "libft.h"
14+
15+
/*
16+
* checks for any printable character including space.
17+
*/
18+
int ft_isprint(int c)
19+
{
20+
if ((c >= 32) && (c <= 126))
21+
return (1);
22+
return (0);
23+
}

0 commit comments

Comments
 (0)