Skip to content

Latest commit

ย 

History

3 Commits

Folders and files

NameName
Last commit message
Last commit date
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿ”ง libft โ€” My First C Project

"Failure is not the opposite of success, it's part of it."

42 School C Made with Love


๐Ÿ“– My Story

I failed the 1337 Piscine.

It hurt. I thought I wasn't cut out for programming. But instead of giving up, I asked myself:

"What if I just kept going anyway?"

So I did. I didn't wait for acceptance. I didn't wait for permission. I grabbed the 42 curriculum, opened up my terminal, and started building libft โ€” the first project in the 42 network.

No teachers. No peers. Just me, the C documentation, and a lot of segmentation faults.

This repository is proof that you don't need to be accepted into 42 to learn like a 42 student. You just need to start.


๐ŸŽฏ What is libft?

libft is a custom implementation of essential C standard library functions. It's the foundation project at 42 School โ€” designed to teach you:

  • ๐Ÿง  How C actually works under the hood
  • ๐Ÿ“ Pointers and memory management (malloc, free, memory leaks)
  • ๐Ÿงฑ Modular programming (writing reusable code)
  • โš™๏ธ Makefiles and compilation pipelines
  • ๐Ÿ› Debugging (valgrind, gdb, and patience)

Instead of relying on <string.h> or <stdlib.h>, you rebuild them yourself. Every function. Every edge case. Every bug.

It's brutal. It's frustrating. And it's exactly what you need to understand C deeply.


๐Ÿ“š Functions Implemented

Character Functions

  • ft_isalpha โ€” checks if character is alphabetic
  • ft_isdigit โ€” checks if character is a digit
  • ft_isalnum โ€” checks if character is alphanumeric
  • ft_isascii โ€” checks if character is ASCII
  • ft_isprint โ€” checks if character is printable
  • ft_toupper โ€” converts to uppercase
  • ft_tolower โ€” converts to lowercase

String Functions

  • ft_strlen โ€” calculates string length
  • ft_strchr โ€” locates character in string
  • ft_strrchr โ€” locates character in string (from the end)
  • ft_strncmp โ€” compares two strings up to n bytes
  • ft_strlcpy โ€” copies string with size limit
  • ft_strlcat โ€” concatenates string with size limit
  • ft_strnstr โ€” locates substring in string
  • ft_strdup โ€” duplicates string (malloc)
  • ft_substr โ€” extracts substring
  • ft_strjoin โ€” concatenates two strings (malloc)
  • ft_strtrim โ€” trims characters from both ends
  • ft_split โ€” splits string by delimiter (malloc)
  • ft_itoa โ€” converts integer to string (malloc)
  • ft_strmapi โ€” applies function to each character
  • ft_striteri โ€” applies function to each character (with index)

Memory Functions

  • ft_memset โ€” fills memory with constant byte
  • ft_bzero โ€” zeros out memory
  • ft_memcpy โ€” copies memory area
  • ft_memmove โ€” copies memory (handles overlap)
  • ft_memchr โ€” locates byte in memory
  • ft_memcmp โ€” compares memory areas
  • ft_calloc โ€” allocates and zeros memory

Conversion Functions

  • ft_atoi โ€” converts string to integer

Output Functions

  • ft_putchar_fd โ€” outputs character to file descriptor
  • ft_putstr_fd โ€” outputs string to file descriptor
  • ft_putendl_fd โ€” outputs string + newline to file descriptor
  • ft_putnbr_fd โ€” outputs integer to file descriptor

๐Ÿ’ก What I Learned

Technical Skills

โœ… Pointers are not scary โ€” they're just addresses. Once you understand that, everything clicks.

โœ… Memory management is critical โ€” every malloc needs a free. Valgrind is your best friend.

โœ… Edge cases matter โ€” NULL pointers, empty strings, size 0... handle them all.

โœ… Makefiles automate builds โ€” make, make clean, make fclean, make re.

โœ… Reading man pages is a superpower โ€” man 3 strlen teaches you more than any tutorial.

โœ… Debugging takes patience โ€” segfaults will test you. Print statements and gdb will save you.

Mindset Shifts

๐Ÿ”ฅ You don't need permission to learn โ€” failing the Piscine doesn't mean you can't code.

๐Ÿ”ฅ Struggle is growth โ€” if it's hard, you're learning.

๐Ÿ”ฅ Build in public โ€” sharing your code makes you accountable and helps others.

๐Ÿ”ฅ Self-teaching is a skill โ€” no one is coming to save you. Figure it out.


๐Ÿš€ How to Use libft

1๏ธโƒฃ Clone the Repository

git clone https://github.com/yourusername/libft.git
cd libft

2๏ธโƒฃ Compile the Library

make

This creates libft.a โ€” a static library you can link to your projects.

3๏ธโƒฃ Use in Your Project

In your C file:

#include "libft.h"

int main(void)
{
    char *str = ft_strdup("Hello from libft!");
    ft_putendl_fd(str, 1);
    free(str);
    return (0);
}

Compile and link:

gcc -Wall -Wextra -Werror main.c -L. -lft -o program
./program

4๏ธโƒฃ Clean Up

make clean    # removes object files
make fclean   # removes object files and libft.a
make re       # recompiles everything from scratch

๐Ÿงช Testing

Manual Testing

I included a comprehensive test file: test_libft.c

make
gcc -Wall -Wextra -Werror test_libft.c -L. -lft -o test_libft
./test_libft

You'll see:

  • โœ… Green checkmarks for passing tests
  • โŒ Red X marks for failing tests
  • A final summary with pass/fail count

External Testers

Use these amazing community testers:

# Example with Tripouille
git clone https://github.com/Tripouille/libftTester.git
cd libftTester
make

Memory Leak Testing

Always check for leaks:

valgrind --leak-check=full ./test_libft

๐Ÿ—‚๏ธ Project Structure

libft/
โ”œโ”€โ”€ Makefile              # Build automation
โ”œโ”€โ”€ libft.h               # Header file with function prototypes
โ”œโ”€โ”€ ft_*.c                # All function implementations
โ”œโ”€โ”€ test_libft.c          # Comprehensive test suite
โ””โ”€โ”€ README.md             # This file

10

๐Ÿ› ๏ธ Compilation Flags

All functions are compiled with:

-Wall -Wextra -Werror

Translation: No warnings. No compromises. Clean code or it doesn't compile.


๐Ÿ“œ Norme (42 Coding Standard)

This project follows the 42 Norm, which enforces:

  • Max 25 lines per function
  • Max 5 functions per file
  • No for loops (only while)
  • Specific naming conventions
  • No memory leaks, no segfaults

Use norminette to check:

norminette *.c *.h

๐ŸŽ“ What's Next?

Now that I've built libft, I'm using it as a foundation for:

  • ๐Ÿš get_next_line โ€” reading files line by line
  • ๐Ÿ–จ๏ธ ft_printf โ€” custom printf implementation
  • ๐Ÿš minishell โ€” building a bash-like shell
  • ๐Ÿงฎ push_swap โ€” algorithm optimization challenges

This is just the beginning.


๐Ÿ’ฌ For Those Who Failed Piscine

If you're reading this because you failed Piscine and you're wondering if you should keep going...

Keep going.

You don't need a school to validate your learning. You don't need acceptance to start building. You just need:

  1. A computer
  2. A compiler
  3. The decision to not give up

I failed. I kept coding. And now I have a working C library that I built from scratch.

You can too.

The 42 curriculum is open source. The knowledge is free. The only thing stopping you is you.

So open your terminal, clone this repo, break it, fix it, and make it yours.

Welcome to the real Piscine โ€” the one that never ends.


๐Ÿค Contributing

Found a bug? Have a suggestion? Want to add a feature?

Feel free to open an issue or submit a pull request. This project is a learning tool โ€” let's make it better together.


๐Ÿ“„ License

This project is open source and available under the MIT License.

Use it. Learn from it. Build on it.


โญ If this inspired you, star the repo and start your own journey.

Don't wait for permission. Just build.


Made with โ˜•, ๐Ÿ›, and ๐Ÿ’ช by someone who refused to quit

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages