libft

by bhagenlo

written for version 15

Your library at 42 School. Your first project.

And therefore, first things first. You're new here, things are overwhelming. That's okay.

And even more so a reason listen carefully to this advice we want to give:

Do not fall into the Macho trap. Not in this project, not in any other. You do not have to have come up with every idea in your code yourself. So do yourself a favor and read some other code. Learning from others is how human society works. Please do not deprive yourself of that opportunity. Deal?

#Prerequisites

For starting your work on the libft, you should know how to:

  • Assign a variable
  • Write a functioning (while(!)-)loop without having off-by-one errors
  • Declare a function
  • Declare and use an array
  • Use a header file
  • Compile your program on the command line
  • (somehow) properly work with pointers

#During

While working on your libft, you'll (need) get to know:

  • How to write a Makefile
  • Function pointers and how they work
  • Allocating memory, meaning:
    • Mallocing the right amount of memory, with the right cast
    • Protecting your malloc()
    • Freeing your memory afterwards, using free()

We think you should also get to know:

  • How to use the VSCode Debugger – at least as soon as you experience your first segfault ;)

Some Tasks where it makes even more sense than normally to think before you start with coding:

  • ft_memmove() – how can you move the content without loss, even when the locations overlap? (and without copying the content?)
  • ft_strlcpy() – are you really sure you know what the man page wants you to do?
  • ft_strlcat() – are you really sure you know what the man page wants you to do?
  • ft_split() – this function is just very, very hard (compared to the others). Acknowledge that, and take your time ;)
  • ft_strmapi() / ft_striteri() – well, make sure you know how to use function pointers ;)

#Cleaning Up

Not so much here, as the subject matter is comparatively clear about the task at hand. However:

  • What value does you ft_strlcat() return? And how many bytes does it append? Is it always NULL-terminating your string?
  • What happens when a malloc inside your ft_split fails? Are you freeing all of previously allocated splits?
  • What does Your Makefile must not relink mean? Did you make sure it does not? How can you check for that?
  • And don't forget about the other checks: Norm, Repo empty, Crashes, Memory Leaks :)

#Aftercare

Are your evals over and Moulinette let you through? Congrats! :)

Let's make sure you memorize stuff you'll need for the future. Some tasks for you:

The modus here is called practice testing – meaning: take some time, don't use help, but just try very hard to retrieve the information. Please check your mistakes immediately afterwards.
  • Write the Makefile for your libft from scratch. The filenames are completely unimportant, rather try to get the overall structure right.
  • Write the header file for the libft from scratch. Same again: The function names are not that important (even though it is nice if you remember them ;)). Try to get the overall structure right.
  • Include some other (arguably even more useful) functions into your libft. An (incomplete) list of ideas:
    • ft_strcmp(char *s1, char *s2)
    • ft_c_isin_str(char c, char *str) – yes, you can also just use ft_strchr for that in a hacky way.
    • ft_str_isin_strs(char *needle, char **needle-box)

And because I don't want to be mean – here is the header code:

int	ft_strcmp(char *s1, char *s2);
int	ft_c_isin_str(char c, char *str);
int	ft_str_isin_strs(char *needle, char **box_of_needles);
With that, you should be good to go. See you :)

#Pointers

← The Holy Graph

Found something to improve? Edit this page on Github!

Born2beroot →