As a student at 1337school, I completed the libft project which involved creating a library of basic C functions. This project required me to implement a variety of functions including memory and string manipulation.
Throughout this project, I sharpened my skills in C programming and gained a deeper understanding of how to manipulate memory and utilize pointers effectively. I also had to consider and implement various edge cases and error handling in each function.
Overall, the libft project was a challenging and rewarding experience that allowed me to develop my skills in C programming and deepen my understanding of the language. I am confident that the skills and knowledge I gained from this project will serve me well in my future projects.
In the 42 journey, our first project is 'libft.' To excel in it, I did a lot of reading to build my knowledge. I focused on helpful resources like old YouTube tutorials and books. For instance, I found a great book that explains pointers well. Additionally, there's a useful PDF about pointers and memory. You can find more valuable information on this website. For advanced C programming, this website is also worth exploring
objects file
Makefile
Makefile tutorial
malloc
DMA
strucut.)
linked_list
function pointer
ovelaping
typecasting
typecasting
type casting
scope of function
file descriptor
open function
This book is awesome
libft is an individual project at 1337 school 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 that we will use in most of our C projects at 1337 school.
Why libft?This project will help us to have a deeper understanding of data structures and algorithms used in C. Also, it will help us to have a better understanding of the standard library functions and how to create our own.
The project contains the following functions:
int ft_atoi(const char *str);
void *ft_bzero(void *s, size_t n);
void *ft_calloc(size_t count, size_t size);
int ft_isalnum(int c);
int ft_isalpha(int c);
int ft_isascii(int c);
int ft_isdigit(int c);
int ft_isprint(int c);
char *ft_itoa(int n);
void *ft_memccpy(void *dest, const void *src, int c, size_t n);
void *ft_memchr(const void *s, int c, size_t n);
int ft_memcmp(const void *s1, const void *s2, size_t n);
void *ft_memcpy(void *dest, const void *src, size_t n);
void *ft_memmove(void *dest, const void *src, size_t n);
void *ft_memset(void *s, int c, size_t n);
void ft_putchar_fd(char c, int fd);
void ft_putendl_fd(char *s, int fd);
void ft_putnbr_fd(int n, int fd);
void ft_putstr_fd(char *s, int fd);
char **ft_split(char const *s, char c);
char *ft_strchr(const char *s, int c);
char *ft_strdup(const char *s1);
char *ft_strjoin(char const *s1, char const *s2);
size_t ft_strlcat(char *dst, const char *src, size_t dstsize);
size_t ft_strlcpy(char *dst, const char *src, size_t dstsize);
size_t ft_strlen(const char *s);
char *ft_strmapi(char const *s, char (*f)(unsigned int, char));
int ft_strncmp(const char *s1, const char *s2, size_t n);
char *ft_strnstr(const char *haystack, const char *needle, size_t len);
char *ft_strrchr(const char *s, int c);
char *ft_strtrim(char const *s1, char const *set);
char *ft_substr(char const *s, unsigned int start, size_t len);
int ft_tolower(int c);
int ft_toupper(int c);
and the following functions that are not part of the mandatory part of the project:
void ft_lstadd_back(t_list **lst, t_list *new);
void ft_lstadd_front(t_list **lst, t_list *new);
void ft_lstclear(t_list **lst, void (*del)(void*));
void ft_lstdelone(t_list *lst, void (*del)(void*));
void ft_lstiter(t_list *lst, void (*f)(void *));
t_list *ft_lstlast(t_list *lst);
t_list *ft_lstmap(t_list *lst, void *(*f)(void *), void (*del)(void *));
t_list *ft_lstnew(void *content);
int ft_lstsize(t_list *lst);
Just an advice, if you are a 1337 student will need the bonus in other projects, I recommend you to do the bonus part of this project.
Because we need to return a pointer to the first character of the string that we created in the function.
if we don't allocate memory for the return value, the string will be created in the stack and will be destroyed when the function returns.
Because malloc returns a void pointer (void *), and we need to cast it to the type of the pointer that we want to return.
small note: in C, void * is a generic pointer that can be casted to any pointer type.
it will work without casting the return value of malloc, but it's not a good practice.
To use the library, clone the repository and compile the files using the Makefile.
you can find some explanations about funcrions in the files of those functions.