8000 GitHub - kitearuba/printf: πŸ–¨οΈ Reimplementation of the C printf() function from scratch. Handles format specifiers, flags, and conversions β€” mimicking real-world output with precision.
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

πŸ–¨οΈ Reimplementation of the C printf() function from scratch. Handles format specifiers, flags, and conversions β€” mimicking real-world output with precision.

Notifications You must be signed in to change notification settings

kitearuba/printf

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

11 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation


πŸ–¨οΈ ft_printf - 42 School Project

ft_printf C Programming Makefile

Welcome to the ft_printf project! This repository contains the implementation of a custom printf() function, a staple of C programming. This project is part of the 42 School curriculum and focuses on variadic functions, memory management, and formatted output.


πŸ“š Table of Contents

  1. πŸ“– Project Overview
  2. βš™οΈ Features
  3. πŸ“‚ Project Structure
  4. πŸ› οΈ Makefile Usage
  5. πŸš€ How to Use
  6. πŸ”„ Relinking and Dependencies
  7. βœ… Norm Compliance
  8. 🎯 Mandatory Part Only
  9. πŸŽ‰ Conclusion
  10. πŸ‘¨β€πŸ’» Author

πŸ“– Project Overview

The ft_printf project replicates the functionality of the standard C printf() function, allowing formatted output to the terminal. By handling variadic arguments and supporting multiple format specifiers, you’ll gain an in-depth understanding of C's capabilities for formatted output.


βš™οΈ Features

The ft_printf function supports various format specifiers, making it versatile for different types of formatted output:

  • Supported Format Specifiers:
    • %c: Print a single character.
    • %s: Print a string.
    • %p: Print a pointer in hexadecimal format.
    • %d / %i: Print a signed decimal integer.
    • %u: Print an unsigned decimal integer.
    • %x: Print a lowercase hexadecimal number.
    • %X: Print an uppercase hexadecimal number.
    • %%: Print a literal percentage sign.

πŸ“‚ Project Structure

The project consists of multiple source and header files, along with the libft library, integrated into the ft_printf implementation. Here’s a snapshot of the project structure:

πŸ“¦ ft_printf
β”œβ”€β”€ πŸ“„ Makefile
β”œβ”€β”€ πŸ“ include
β”‚   └── πŸ“„ ft_printf.h
β”œβ”€β”€ πŸ“ libft
β”‚   β”œβ”€β”€ πŸ“„ libft.h
β”‚   β”œβ”€β”€ πŸ“„ Makefile
β”‚   └── πŸ“„ [Libft source files...]
β”œβ”€β”€ πŸ“ src
β”‚   β”œβ”€β”€ πŸ“„ ft_printf.c
β”‚   β”œβ”€β”€ πŸ“„ [Additional source files...]
└── πŸ“¦ libftprintf.a

πŸ› οΈ Makefile Usage

The Makefile provides several commands to help with the compilation and management of your project:

Command Description
make Compile the libftprintf.a library.
make clean Remove object files.
make fclean Remove object files and libraries.
make re Clean and recompile everything.

🧹 Cleaning Targets

  • make clean: Deletes all .o files generated during the build process, but keeps the libraries.
  • make fclean: Deletes both the object files and the compiled library (libftprintf.a).
  • make re: Cleans and recompiles the entire project, ensuring all files are up to date.

πŸš€ How to Use

1️⃣ Include the Header

To use ft_printf in your project, include the ft_printf.h header file in your source code:

#include "ft_printf.h"

2️⃣ Compile the Library

Run the following command to compile the libftprintf.a library:

make

3️⃣ Link the Library

To use libftprintf.a in your own project, link it during compilation:

gcc your_program.c -I./include/ -I./libft/ -L. -lftprintf -o your_program 

4️⃣ Example Usage

Here’s an example showing how to use ft_printf in your C program:

#include "ft_printf.h"

int main(void)
{
    ft_printf("Hello, %s!\n", "42");
    return 0;
}

πŸ”„ Relinking and Dependencies

The project is designed to avoid unnecessary relinking. If changes are made to any of the source or header files in the libft or ft_printf directories, the Makefile will automatically detect these changes and recompile the affected files.


βœ… Norm Compliance

The project adheres to the 42 Norm standards, ensuring:

  • No memory leaks: Proper memory management and freeing of allocated memory.
  • No forbidden functions: Only allowed functions are used.
  • Structured code: Clean, well-organized, and readable code with appropriate error handling.
  • Error-free compilation: The project compiles without warnings or errors and runs without crashes.

🎯 Mandatory Part Only

Currently, this project includes only the mandatory part of the ft_printf assignment. The bonus features, such as additional formatting flags, field width, and precision specifiers, have not yet been implemented.


πŸŽ‰ Conclusion

The ft_printf project is an excellent exercise in C programming, particularly for gaining a deeper understanding of variadic functions, formatted output, and manual memory management. Building this library from scratch will equip you with valuable skills that can be applied in more advanced projects down the line.

Good luck, and happy coding! πŸš€


πŸ‘¨β€πŸ’» Author

chrrodri
42 Barcelona

GitHub Profile


Bonus version (printf_bonus) will be added in the future.


About

πŸ–¨οΈ Reimplementation of the C printf() function from scratch. Handles format specifiers, flags, and conversions β€” mimicking real-world output with precision.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published
0