Skip to content

A basic C library with useful standard functions.

Notifications You must be signed in to change notification settings

celinenguyentu/Libft

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Libft

This project is about coding a C library. C programming can be very tedious when one doesn’t have access to the highly useful standard functions. This project is about understanding the way these functions work, implementing and learning to use them. It will contain a lot of general purpose functions future programs of the 42 cursus will rely upon.

Grade : 125/100
Subjects v.16.1 : FR EN
42 Norm v.4 : FR EN

Content

Functions from <ctype.h>

Functions from <string.h>

Functions from <stdlib.h>

  • ft_atoi - converts a string to an integer
  • ft_calloc - allocates memory and sets its bytes' values to 0

Non-standard functions

  • ft_substr - returns a substring from a string
  • ft_strjoin - concatenates two strings
  • ft_strtrim - trims the beginning and end of string with specific set of chars
  • ft_split - splits a string using a char as parameter
  • ft_itoa - converts a number into a string
  • ft_strmapi - applies a function to each character of a string
  • ft_striteri - applies a function to each character of a string
  • ft_putchar_fd - outputs a char to a file descriptor
  • ft_putstr_fd - outputs a string to a file descriptor
  • ft_putendl_fd - outputs a string to a file descriptor, followed by a new line
  • ft_putnbr_fd - outputs a number to a file descriptor

Linked list functions (Bonus Part)

  • ft_lstnew - creates a new list element
  • ft_lstadd_front - adds an element at the beginning of a list
  • ft_lstsize - counts the number of elements in a list
  • ft_lstlast - returns the last element of a list
  • ft_lstadd_back - adds an element at the end of a list
  • ft_lstclear - deletes and free list
  • ft_lstiter - applies a function to each element of a list
  • ft_lstmap - applies a function to each element of a list and returns a new list with the return of all nodes iteration

Usage

Makefile targets

  • makeor make all - compile library libft.a without bonus functions
  • make bonus - compile library libft.a with bonus functions
  • make clean - remove all object files
  • make fclean - remove all object files and library libft.a
  • make re - remove all object files and library libft.a, and recompile library without bonus

Use the library in your code

After compiling the library libft.a, include the header in your code :

#include "libft.h"

Compile your main.c code using

[ gcc | clang | cc ] main.c -I path/to/libft.h -L path/to/libft.a -lft

Alternatively, if your main.c file is located at the root of this repository :

[ gcc | clang | cc ] main.c libft.a

Testers

I recommend you to code your own tests and compare your function to the existing libc function when you can. It is not only an important part of the learning process but also allows to properly imitate the behaviour of the libc that your system uses. Those are third-party tester to run complementary tests, use them at your own risk.