This repository contains a complete implementation of three foundational C libraries: libft
, printf
, and gnl
(Get Next Line). Each library is designed to be modular and can be used independently for various projects. You can compile them separately using the commands make libft
, make printf
, and make gnl
. Ensure you include the respective header files in your projects for proper functionality.
libft
is a personalized implementation of commonly used standard C library functions. It includes utilities for string manipulation, memory handling, linked lists, and more.
- Custom replacements for standard functions such as
strlen
,memset
, andstrncpy
. - Extended utilities like
ft_split
for splitting strings andft_itoa
for integer-to-string conversion. - Basic linked list operations: create, add, remove, and iterate through list elements.
ft_strlen
: Calculate the length of a string.ft_itoa
: Convert an integer to a string.ft_split
: Split a string into an array using a delimiter.ft_lstnew
: Create a new linked list node.
printf
is a simplified recreation of the standard printf
function, supporting formatted output for various data types.
- Format Specifiers:
%d
,%i
,%u
,%x
,%X
,%c
,%s
,%p
, and%%
. - Modifiers: Handles width, precision, and flags like
-
,+
,0
,#
, and space. - Easy-to-integrate solution for formatted output in embedded or custom systems.
ft_printf("Hello, 42! This is an integer: %d and a hex: %x\n", 42, 255);
gnl
provides an efficient way to read lines from file descriptors, even for large files or when managing multiple files simultaneously.
- Reads one line at a time, making it memory-efficient for large files.
- Handles multiple file descriptors concurrently.
- Avoids memory leaks through robust buffer management.
To build the libraries:
make
This will create the libft.a
archive containing all three libraries.
You can compile each library independently:
make libft
make printf
make gnl
- Add the header files:
#include "libft.h" #include "pr_printf.h" #include "get_next_line.h"
- Link the compiled archive:
cc -Wall -Wextra -Werror -Iincludes <your_file.c> libft.a -o <your_output>
Here's a combined test program to showcase the capabilities of all three libraries:
#include "libft.h"
#include "pr_printf.h"
#include "get_next_line.h"
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
int main(void) {
// Testing LIBFT
printf("=== LIBFT ===\n");
char *str = ft_strdup("Hello, Libft!");
printf("Duplicated string: %s\n", str);
free(str);
// Testing PRINTF
printf("\n=== PRINTF ===\n");
ft_printf("Formatted output: Integer: %d, Hex: %x, String: %s\n", 42, 255, "Hello!");
// Testing GNL
printf("\n=== GET NEXT LINE ===\n");
int fd = open("test_file.txt", O_RDONLY);
if (fd < 0) {
perror("Error opening file");
return 1;
}
char *line;
while ((line = get_next_line(fd)) != NULL) {
printf("%s", line);
free(line);
}
close(fd);
return 0;
}
To compile and run:
cc -Wall -Wextra -Werror -Iincludes test.c libft.a -o test_program
./test_program
This project is released under the MIT License. For details, refer to the LICENSE file.
- Romain - Github : rom98759