Skip to content
/ libft Public

My implementation of some of the Standard C Library functions including some additional ones.

Notifications You must be signed in to change notification settings

Fr3ud/libft

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Libft

My implementation of some of the Standard C Library functions including some additional ones.

TOC

What is libft?

Libft is an individual project at UNIT Factory (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, UNIT Factory (42) makes us do this just so we can have a deeper understanding of data structures and basic algorithms. At UNIT Factory (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.

What's in it?

As you can see from the Project instructions, there are 4 sections:

  1. Libc Functions: Some of the standard C functions
  2. Additional functions: Functions UNIT Factory (42) deems will be useful for later projects
  3. Bonus Functions: Functions UNIT Factory (42) deems will be useful for linked list manipulation
  4. Personal Functions: Functions I believe will be useful later.
Libc functions Additional functions Bonus Functions Personal Functions
memset ft_memalloc ft_lstnew ft_iswhitespace
bzero ft_memdel ft_lstdelone ft_w_count
memcpy ft_strnew ft_lstdel ft_swap
memccpy ft_strdel ft_lstadd ft_hex_to_int
memmove ft_strclr ft_lstiter ft_pow
memchr ft_striter ft_lstmap ft_bye
memcmp ft_striteri get_next_line
strlen ft_strmap
strdup ft_strmapi
strcpy ft_strequ
strncpy ft_strnequ
strcat ft_strsub
strlcat ft_strjoin
strchr ft_strtrim
strrchr ft_strsplit
strstr ft_itoa
strnstr ft_putchar
strcmp ft_putstr
strncmp ft_putendl
atoi ft_putnbr
isalpha ft_putchar_fd
isdigit ft_putstr_fd
isalnum ft_putendl_fd
isascii ft_putnbr_fd
isprint
toupper
tolower

Notes:

  • Most of the the files and function names are namespaced with an ft in front. It stands for Fourty Two
  • I update this list almost every month with new personal functions.

How does it work?

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 UNIT Factory (42).

To create that library, after downloading/cloning this project, cd into the project, copy all the files from the sub folders to the root directory and finally, call make:

git clone https://github.com/Fr3ud/libft
cd libft
make

You should see a libft.a file and some object files (.o).

Now to clean up (removing the .o files), call make clean

How do I use the library?

I added an example file called example.c, it's using the function ft_putstr to print "DON'T PANIC" to the screen.

If you try to compile it with gcc using gcc example.c you will get an undefined symbol error for ft_putstr.

You have to tell the file where your library resides and which library it is using:

gcc example.c -L. -lft

-L takes the path to your library. . in this case
-l takes the name of your library. This is the set of characters that come after lib in your library name.

That's it. Now run it using ./a.out

How do I test it? How do I test my own implementations?

To test the code we're going to be using @alelievr's Libft Unit Test. There are some good others but I'll only be covering this one.

1. To test the code in this repo

  1. Clone this repo and cd into it, make sure it's called libft:

     git clone https://github.com/Fr3ud/libft
     cd libft/
    
  2. Run Make so you can build the library:

     make
    
  3. Go back to the root directory and download @alelievr's Libft Unit Test:

     cd ..
     git clone https://github.com/alelievr/libft-unit-test
    
  4. 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.

That's it! If you're having some problems, just send me a tweet. If you think your problem is due to my code or this README, create a new issue. I'll definitely check it out.

Example usage

This is a list of my projects that use Libft extensively:

Enjoy.

About

My implementation of some of the Standard C Library functions including some additional ones.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published