Skip to content

hamza-cskn/42-libft

Repository files navigation

42-libft

Your very first own library

Moulinette

Passed with 125/100 at 11 July 2023

Summary

This project is about coding a C library. It will contain a lot of general purpose functions your programs will rely upon. Some of them are replicas of original C functions.

Mandatory Part

Program Name Turn in files Makefile External functs. Libft authorized Description
libft.a Makefile, libft.h, ft_*.c NAME, all, clean, fclean, re Detailed below N/A Write your own library.

Libc Functions

Here are 42 implementations of libc. The implementations have the 'ft_' prefix.

  • isalpha - Check if a character is alphabetic.
  • isdigit - Check if a character is a decimal digit.
  • isalnum - Check if a character is alphabetic or a digit.
  • isascii - Check if a character is a 7-bit ASCII character.
  • isprint - Check if a character is printable.
  • strlen - Calculate the length of a string.
  • memset - Fill memory with a constant byte.
  • bzero - Set the first n bytes of memory to zero.
  • memcpy - Copy memory from source to destination.
  • memmove - Copy memory, handling overlapping areas.
  • strlcpy - Safely copy a string into a fixed-size buffer.
  • strlcat - Safely concatenate strings into a fixed-size buffer.
  • toupper - Convert a character to uppercase.
  • tolower - Convert a character to lowercase.
  • strchr - Find the first occurrence of a character in a string.
  • strrchr - Find the last occurrence of a character in a string.
  • strncmp - Compare two strings up to a specified length.
  • memchr - Locate the first occurrence of a character in a memory block.
  • memcmp - Compare two memory blocks up to a specified length.
  • strnstr - Locate a substring in a string, limiting the search to a specified length.
  • atoi - Convert a string to an integer.
  • calloc - Allocate and zero-initialize memory.
  • strdup - Duplicate a string.

Additional Functions

These functions are not in the libc library.

Prototype: char *ft_substr (char const *s, unsigned int start, size_t len);
Parameters:

  • s: The string from which to create the substring.
  • start: The start index of the substring in the string 's'.
  • len: The maximum length of the substring.


Return value:

  • The substring.
  • NULL if the allocation fails.


Description: Allocates (with malloc(3)) and returns a substring from the string 's'. The substring begins at index 'start' and is of maximum size 'len'.


Prototype: char *ft_strjoin(char const *s1, char const *s2) ;
Parameters:

  • s1: The prefix string.
  • s2: The suffix string.


Return value:

  • The new string.
  • NULL if the allocation fails.


Description: Allocates (with malloc(3)) and returns a new string, which is the result of the concatenation of 's1' and 's2'.


Prototype: char *ft_strtrim(char const *s1, char const *set);
Parameters:

  • s1: The string to be trimmed.
  • set: The reference set of characters to trim.


Return value:

  • The trimmed string.
  • NULL if the allocation fails.


Description: Allocates (with malloc(3)) and returns a copy of 's1' with the characters specified in 'set' removed from the beginning and the end of the string.

Prototype: char **ft_split(char const *s, char c);
Parameters:

  • s: The string to be split.
  • c: The delimiter character.


Return value:

  • The array of new strings resulting from the split.
  • NULL if the allocation fails.


Description: Allocates (with malloc(3)) and returns an array of strings obtained by splitting 's' using the character 'c' as a delimiter. The array must end with a NULL pointer.


Prototype: char *ft_itoa(int n);
Parameters:

  • n: the integer to convert.


Return value:

  • The string representing the integer.
  • NULL if the allocation fails.


Description: Allocates (with malloc(3)) and returns a string representing the integer received as an argument. Negative numbers must be handled.


Prototype: char *ft_strmapi(char const *s, char (*f)(unsigned int, char));
Parameters:

  • s: The string on which to iterate.
  • f: The function to apply to each character.


Return value:

  • The string created from the successive applications of 'f'.
  • Returns NULL if the allocation fails.


Description: Applies the function 'f' to each character of the string 's', passing its index as the first argument to create a new string (with malloc(3)) resulting from successive applications of 'f'.


Prototype: void ft_striteri(char *s, void (f)(unsigned int, char));
Parameters:

  • s: The string on which to iterate.
  • f: The function to apply to each character.


Return value: None
Description: Applies the function 'f' on each character of the string passed as an argument, passing its index as the first argument. Each character is passed by address to 'f' to be modified if necessary.


Prototype: void ft_putchar_fd(char c, int fd);
Parameters:

  • c: The character to output.
  • fd: The file descriptor on which to write.


Return value: None
Description: Outputs the character 'c' to the given file descriptor.


Prototype: void ft_putstr_fd(char *s, int fd);
Parameters:

  • s: The string to output.
  • fd: The file descriptor on which to write.


Return value: None
Description: Outputs the string 's' to the given file descriptor.


Prototype: void ft_putendl_fd(char *s, int fd);
Parameters:

  • s: The string to output.
  • fd: The file descriptor on which to write.


Return value: None
Description: Outputs the string 's' to the given file descriptor followed by a newline.


Prototype: void ft_putnbr_fd(int n, int fd);
Parameters:

  • n: The integer to output.
  • fd: The file descriptor on which to write.


Return value: None
Description: Outputs the integer 'n' to the given file descriptor.

Compiling

  1. Clone the repository.
  2. Go inside of the repository downloaded: cd 42-libft
  3. Use make all command at directory of the repository.

About

Implementation of the famous libc library.

Topics

Resources

Stars

Watchers

Forks