An open API service indexing awesome lists of open source software.

https://github.com/oviqa/1337-libft

A custom C library implementation recreating essential functions from the standard C library (libc). This foundational project involves coding functions like strlen, strcpy, memset, and more from scratch, providing deep understanding of memory management, string manipulation, and low-level programming concepts.
https://github.com/oviqa/1337-libft

c c-programming-language calloc

Last synced: 9 months ago
JSON representation

A custom C library implementation recreating essential functions from the standard C library (libc). This foundational project involves coding functions like strlen, strcpy, memset, and more from scratch, providing deep understanding of memory management, string manipulation, and low-level programming concepts.

Awesome Lists containing this project

README

          

# ๐Ÿ“š Libft - My First C Library

> *"The beginning of wisdom is the definition of terms."* - Socrates

**Libft** is my implementation of essential C standard library functions, created as the foundational project at **1337 School**. This project taught me the fundamentals of C programming by rebuilding core functions from scratch.

## ๐ŸŽฏ Project Overview

The goal was to create my own C library containing a collection of functions that are essential for C programming. This library serves as the foundation for all future projects at 1337 School.

### What I Built
- **42 functions** recreating essential libc functions
- **Memory management** functions
- **String manipulation** utilities
- **Character validation** functions
- **Linked list** manipulation functions (bonus part)

## ๐Ÿ› ๏ธ Functions Implemented

### Part 1 - Libc Functions
Functions that exist in the C standard library:

| Function | Description |
|----------|-------------|
| `ft_strlen` | Calculate string length |
| `ft_strcpy` | Copy strings |
| `ft_strcmp` | Compare strings |
| `ft_memset` | Fill memory with bytes |
| `ft_memcpy` | Copy memory area |
| `ft_isalpha` | Check if alphabetic |
| `ft_isdigit` | Check if digit |
| `ft_toupper` | Convert to uppercase |
| `ft_tolower` | Convert to lowercase |
| And many more... |

### Part 2 - Additional Functions
Functions not in libc or with different prototypes:

| Function | Description |
|----------|-------------|
| `ft_substr` | Extract substring |
| `ft_strjoin` | Concatenate strings |
| `ft_strtrim` | Trim characters from string |
| `ft_split` | Split string by delimiter |
| `ft_itoa` | Convert integer to string |
| `ft_putchar_fd` | Output char to file descriptor |
| `ft_putstr_fd` | Output string to file descriptor |

### Bonus Part - Linked Lists
| Function | Description |
|----------|-------------|
| `ft_lstnew` | Create new list element |
| `ft_lstadd_front` | Add element at beginning |
| `ft_lstsize` | Count list elements |
| `ft_lstlast` | Get last element |
| `ft_lstadd_back` | Add element at end |
| `ft_lstclear` | Delete and free list |

## ๐Ÿš€ How to Use

### Compilation
```bash
# Compile the library
make

# Compile with bonus functions
make bonus

# Clean object files
make clean

# Clean everything
make fclean

# Recompile everything
make re
```

### Usage Example
```c
#include "libft.h"
#include

int main(void)
{
char *str = "Hello, 1337!";
char *substr;

printf("Original: %s\n", str);
printf("Length: %zu\n", ft_strlen(str));

substr = ft_substr(str, 7, 4);
printf("Substring: %s\n", substr);

free(substr);
return (0);
}
```

### Compilation with Your Project
```bash
gcc -Wall -Wextra -Werror your_program.c -L. -lft -o your_program
```

## ๐Ÿ“‹ Requirements & Norms

- **Language**: C
- **Norm**: 1337/42 School coding standard
- **Functions**: No global variables
- **Memory**: All heap-allocated memory must be freed
- **Error handling**: Functions should not crash unexpectedly

### Compilation Flags
```bash
-Wall -Wextra -Werror
```

## ๐ŸŽ“ What I Learned

This project was crucial for understanding:

- **Memory Management**: Manual allocation and deallocation
- **Pointer Manipulation**: Working with different levels of indirection
- **String Operations**: Understanding how strings work at a low level
- **Linked Lists**: Dynamic data structures and memory allocation
- **Makefile**: Automating compilation process
- **Code Organization**: Structuring a library project
- **Testing**: Writing comprehensive tests for each function

## ๐Ÿงช Testing

I created comprehensive tests to verify each function works correctly:

```bash
# Example test structure
make test
./test_libft
```

## ๐Ÿ“ Project Structure

```
libft/
โ”œโ”€โ”€ src/ # Source files (.c)
โ”œโ”€โ”€ include/ # Header files (.h)
โ”œโ”€โ”€ Makefile # Compilation rules
โ””โ”€โ”€ README.md # This file
```

## ๐Ÿ’ญ Reflections

Building Libft from scratch gave me a deep appreciation for the standard library functions we often take for granted. Every `strlen()` call, every `malloc()`, every string operation - I now understand what happens under the hood.

This project laid the foundation for all my subsequent C projects at 1337 School and taught me the importance of:
- Writing clean, readable code
- Proper memory management
- Comprehensive testing
- Following coding standards

---

*This project was completed as part of the 1337 School curriculum (42 Network).*

**Author**: Hiba
**School**: 1337 (42 Network)
**Year**: 2024