Libft is an individual project at 42 that requires us to re-create some standard C library functions including some additional ones that can be used later to build a library of useful functions for the rest of the program.
Disclaimer: Reinventing the wheel is bad, 42 makes us do this just so we can have a deeper understanding of data structures and basic algorithms. At 42 we're not allowed to use some standard libraries on our projects, so we have to keep growing this library with our own functions as we go farther in the program.
According to project's pdf there should be 4 sections:
- Libc Functions: Some of the standard C functions.
- Additional functions: Functions 42 deems will be useful for later projects.
- Bonus Functions: Functions 42 deems will be useful for linked list manipulation.
- Personal Functions: Functions I believe will be useful later.
However, I've decided reorganize and combined functions to several folders:
- chars: Basic functions to work with char type
- get_next_line: GNL project integrated into libft for convenience. See project page
- math: Basic math functions. (This part will be
probablyextended in the future). See notes - memory: Memory operations(allocation, freeing etc.)
- output: Functions for printing output (except for ft_printf)
- ft_printf: My implementation of printf functions. See project page
- list: Functions for manipulations with linked lists.
- matrix: Functions for manipulation with generic matrix. See notes
- numbers: Functions related to integer number types(shor, int etc.).
- strings: Part of <string.h> functions and addition functions which I deemed useful to work with string.
- structures: My implementation of some data structures(queue, stack etc.)
My code is not the best, but it passed all the 42 tests successfully and I successfully used in my other 42 projects
- Most of the the files and function names are namespaced with an ft in front. It stands for Forty Two
- The project instructions require that we put all the source files in the root directory but for the sake of this Github repo, I separate them into sub folders according to classification above.
- I update this list almost every month with new personal functions. If you don't know what a function does, refer to the Wiki, where I document all my personal functions.
The goal is to create a library called libft.a from the source files so I can later use that library from other projects at 42.
To create that library, after downloading/cloning this project, cd into the project and call make:
git clone https://github.com/IvanKozlov95/libft
cd libft
make
You should see a libft.a file and some object files (.o).
That's it! If you're having some problems, just send me an email here: [email protected]. If you're 42 student fill free to message me on slack. If you think your problem is due to my code or this README, create a new issue. I'll definitely check it out.
To test the code we're going to be using @alelievr's Libft Unit Test.
-
Clone this repo, make sure it's called
libft
:git clone https://github.com/IvanKozlov95/libft libft
-
Clone @alelievr's test repo:
git clone https://github.com/alelievr/libft-unit-test
-
Go into the test folder and run the test:
cd libft-unit-test make f
If you did everything correctly you should get a cool list of tests showing you the function names and if they passed or not.
I added an example file called hello_world.c in srcs/test folder, it's using the function ft_printf to print "Hello world!" on the screen.
To get the output follow steps below:
-
Inside project directory run make command:
make
-
Compile srcs/test/hello_world.c explicitly specifying ft library and includes directory:
gcc srcs/test/hello_world.c -L . -l ft -I includes
-
Run the a.out executable:
./a.out
If you did everything right you will see this output:
$ Hello world!
Fill free to modify test file or add your own. Don't forget to add header to the c files. All header are in includes/ directory and have the same name as classifications above.
This is a list of my projects that use Libft extensively: