/printf_42

ft_printf - A custom implementation of the printf function in C! ๐Ÿ› ๏ธ This project is a deep dive into variadic functions, formatted output, and memory management, providing a foundational understanding of how one of the most essential functions in C works. ๐ŸŒŸ

Primary LanguageCMIT LicenseMIT

๐Ÿ“Š ft_printf

Overview

Welcome to ft_printf! ๐ŸŽ‰ This project is part of the 42 curriculum, where you will implement your own version of the C standard library function printf. By doing this, you'll gain a deeper understanding of variadic functions, formatted output, and string manipulation in C. ๐Ÿ› ๏ธ

๐Ÿš€ Features

  • Basic Conversion Specifiers: Supports %c, %s, %p, %d, %i, %u, %x, and %X.
  • Bonus Features: Add support for additional flags like #, 0, -, (space), and +.
  • Memory Management: Proper handling of memory allocation and freeing for dynamic strings.

๐Ÿ› ๏ธ Function Prototype

int ft_printf(const char *format, ...);
  • format: The string containing the text to be written to the standard output, optionally containing format specifiers that are replaced by the values of additional arguments.

Example Usage

ft_printf("Hello, %s!\n", "world");
ft_printf("Number: %d, Hex: %x\n", 42, 42);

๐Ÿ“‹ Project Structure

|-- srcs/
|   |-- ft_printf.c           # Main ft_printf logic
|   |-- ft_printf.h           # Header file with prototypes and macros
|   |-- ft_putchar_n_count.c  # Helper function to print a character and count it
|   |-- ft_putstr_n_count.c   # Helper function to print a string and count it
|   |-- ft_putnbr_n_count.c   # Helper function to print a number and count it
|   |-- ft_puthexa_n_count.c  # Helper function to print a hexadecimal number and count it
|   |-- ft_putptr_n_count.c   # Helper function to print a pointer address and count it
|-- Makefile                  # Makefile to compile the project
|-- main.c                    # Test file for ft_printf implementation

๐Ÿงช Testing

To compile and test your ft_printf function, use the provided Makefile:

make
./ft_printf

You can also create your own test cases in main.c to verify the behavior of your implementation against the standard printf function.

๐Ÿงฉ Learning Objectives

By completing this project, you will:

  • Gain a deep understanding of how formatted output functions work in C.
  • Improve your skills in handling variable argument lists with va_list.
  • Enhance your ability to manage and format different data types.

๐ŸŒŸ Bonus Objectives

For those looking to go above and beyond, consider adding support for the following:

  • Additional Flags: Implement support for #, 0, -, (space), and +.
  • Width and Precision: Handle the width and precision fields in the format specifiers.

๐Ÿ“œ License

This project is released under the MIT License. Feel free to fork, learn, and contribute! ๐Ÿค


Happy coding! ๐Ÿง‘โ€๐Ÿ’ป