/libft_42sp

Libft is the first project of the 42cursus.

Primary LanguageC

Libft

📚 Your very first own library.

Libft is the first project of the 42cursus. The aim is to recode several functions from the standard C library and some additional functions that may be used throughout the course.

Why is libft important?

This project allows students to work with the basics of the language. Pointers, memory allocation, operations with data structures, as well as the creation of header and Makefile files.

Grade and Badge

image image

Skills

  • Algorithms & AI
  • Imperative programming
  • Rigor

Mandatory part

Libc functions

function description
ft_isascii tests if a given character, in the current locale, can be represented as a valid 7–bit US-ASCII character.
ft_isprint checks whether a character is a printable character or not.
ft_isalpha checks if the passed character is alphabetic.`
ft_isdigit checks if the passed character is a decimal digit character.
ft_isalnum checks if the passed character is alphanumeric.
ft_tolower converts a given letter to lowercase.
ft_toupper converts a given letter to uppercase.
ft_strlen computes the length of the string str up to, but not including the terminating null character.
ft_strchr searches for first occurrence of c in the string *str.
ft_strrchr searches for the last occurrence of the character c (an unsigned char) in the string pointed to, by the argument str.
ft_strnstr locates the first occurrence of the null-terminated string pointed by little in string pointed by big. Characters that appear after a '\0' or len are not searched.
ft_strncmp compares at most the first n bytes of str1 and str2.
ft_strlcpy copies up to size - 1 characters from the NUL-terminated string src to dest, NUL-terminating the result.
ft_strlcat appends the NUL-terminated string src to the end of dest. It will append at most size - strlen(dst) - 1 bytes, NUL-terminating the result.
ft_strdup returns a pointer to a new string duplicated of the string s. Memory for the new string is obtained with malloc.
ft_atoi converts the initial portion of the string pointed to by str to int.
t_memset fills memory with a constant byte.
ft_bzero copies n bytes, each with a value of zero, into string s.
ft_memcpy copies n bytes from memory area src to memory area dest. The memory areas must not overlap. Use ft_memmove if the memory areas do overlap.
ft_memmove copies n bytes from memory area src to memory area dest and will not be corrupted if memory areas do overlap.
ft_memchr Searches within the first n bytes of the block of memory pointed by str for the first occurrence of c (interpreted as an unsigned char), and returns a pointer to it.
ft_memcmp compares n byte string s1 against n byte string s2.
ft_calloc allocates size bytes and returns a pointer to the allocated memory. The memory is not initialized.

Additional functions

In this second part, students must code a set of functions that are either not included in the libc, or included in a different form.

function description
ft_substr allocates (with malloc) and returns a substring from the string s. The substring begins at index start and is of maximum size len.
ft_strjoin allocates (with malloc) and returns a new string, which is the result of the concatenation of s1 and s2.
ft_strtrim allocates (with malloc) and returns a copy of s1 with the characters specified in set removed from the beginning and the end of the string
ft_split allocates (with malloc) and returns an array of strings obtained by splitting s using the character c as a delimiter. The array must beended by a NULL pointer.
ft_itoa allocates (with malloc) and returns a string representing the integer received as an argument. Negative numbers must be handled.
ft_strmapi applies the function f to each character of the string s to create a new string (with malloc) resulting from successive applications of f.
ft_striteri applies the function f to each character of the string passed as argument, and passing its index as first argument. Each character is passed by address to f to be modified if necessary.
ft_putchar_fd outputs the character c to the given file descriptor.
ft_putstr_fd outputs the string s to the given file descriptor.
ft_putendl_fd outputs the string s to the given file descriptor, followed by a newline.
ft_putnbr_fd outputs the integer n to the given file descriptor.