This project was created as part of the 42 Common Core curriculum.
Libft is a C programming project that consists of creating a personal library by reimplementing several standard C library functions and developing additional utility functions.
The purpose of the project is to improve understanding of fundamental C concepts such as pointers, memory management, strings, dynamic memory allocation, file descriptors, function pointers, static libraries, Makefiles, and linked lists.
The final result is a static library called libft.a, which can be reused in future C projects.
ft_isalphaft_isdigitft_isalnumft_isasciift_isprintft_toupperft_tolower
ft_strlenft_strchrft_strrchrft_strncmpft_strlcpyft_strlcatft_strnstrft_strdup
ft_memsetft_bzeroft_memcpyft_memmoveft_memchrft_memcmpft_calloc
ft_atoift_substrft_strjoinft_strtrimft_splitft_itoaft_strmapift_striteri
ft_putchar_fdft_putstr_fdft_putendl_fdft_putnbr_fd
ft_lstnewft_lstadd_frontft_lstsizeft_lstlastft_lstadd_backft_lstdeloneft_lstclearft_lstiterft_lstmap
The project includes a Makefile.
To compile the library:
makeThis creates:
libft.a
Available Makefile commands:
make
make clean
make fclean
make remakecompiles the source files and createslibft.a.make cleanremoves object files.make fcleanremoves object files andlibft.a.make reperforms a complete rebuild of the library.
Include the Libft header in your C program:
#include "libft.h"Then compile your program together with the library:
cc -Wall -Wextra -Werror main.c libft.a -o programRun the program with:
./programExample:
#include "libft.h"
#include <stdio.h>
int main(void)
{
char *str;
str = ft_strdup("Hello, Libft!");
if (str == NULL)
return (1);
printf("%s\n", str);
free(str);
return (0);
}Compile it with:
cc -Wall -Wextra -Werror main.c libft.a -o programThe project also includes functions for working with singly linked lists.
Each node is represented by:
typedef struct s_list
{
void *content;
struct s_list *next;
} t_list;Each node contains:
content: a pointer to the data stored in the node.next: a pointer to the next node in the list.
The linked list functions allow nodes to be created, added, counted, traversed, deleted, cleared, and transformed.
During this project, I practiced and improved my understanding of:
- Pointers and pointer arithmetic
- Dynamic memory allocation
mallocandfree- Memory leaks and memory management
- Strings and character manipulation
- Memory manipulation
- Function pointers
- File descriptors
- The
writesystem call - Static libraries
- Makefiles
- Header files
- Structures
- Linked lists
- Error handling
- Debugging C programs
- Using compiler warnings effectively
The project also helped me understand the importance of handling edge cases and checking the result of memory allocations.
The project was compiled using:
cc -Wall -Wextra -WerrorThe source files were also checked using Norminette.
Example:
norminetteThe library was tested with different inputs, edge cases, and external Libft testers.
Memory-related behavior can also be checked using Valgrind when available.
Example:
valgrind --leak-check=full ./programThe following resources were useful while working on the project:
- 42 Libft subject and project documentation
- C manual pages
- Linux manual pages
- Compiler error and warning messages
- Norminette
- Valgrind
- Libft testing tools
- General C documentation and references
Useful manual commands include:
man malloc
man free
man write
man strlen
man strchr
man memcpyAI tools were used as a learning and debugging aid during the development of this project.
They were mainly used to:
- Explain C programming concepts
- Clarify pointer behavior
- Understand dynamic memory allocation
- Understand function pointers
- Understand linked lists
- Review implementation logic
- Explain compiler and linker errors
- Help identify possible edge cases
- Explain testing results
AI was used to support the learning process rather than replace it.
The implementations were reviewed, compiled, tested, debugged, and understood during development.
aalhammo
42 Common Core