Skip to content

The goal of this project is pretty straightforward. Recode printf(). using a variable number of arguments.

License

Notifications You must be signed in to change notification settings

pix3l-p33p3r/ft_printf

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ft_printf
ft_printf

Final Score

Final Score

Completed

Overview

ft_printf is a custom implementation of the standard C library function printf. The goal of this project is to recreate printf with similar functionality, handling formatted output to the standard output stream.

Features

  • Supports the following conversions:
    • %c: Character
    • %s: String
    • %p: Pointer
    • %d / %i: Signed decimal integer
    • %u: Unsigned decimal integer
    • %x / %X: Unsigned hexadecimal integer (lowercase/uppercase)
    • %%: Percent sign
  • Handles the following flags:
    • -: Left justify
    • 0: Zero-padding
    • .precision: Precision for strings and integers
    • Field width specification

Installation

To use ft_printf, you can clone the repository and compile the source code as follows:

git clone https://github.com/pix3l-p33p3r/ft_printf.git
cd ft_printf
make

This will generate a libftprintf.a static library that you can link with your projects.

Usage

To use ft_printf in your C programs, include the header and link the library during compilation:

#include "ft_printf.h"

Compile your program with ft_printf:

gcc -Wall -Wextra -Werror -L. -lftprintf your_program.c -o your_program

Example

Here’s a quick example of how you can use ft_printf:

#include "ft_printf.h"

int main(void)
{
    ft_printf("Hello, %s!\n", "world");
    ft_printf("Number: %d\n", 42);
    ft_printf("Hex: %#x\n", 255);
    return 0;
}

Output

Hello, world!
Number: 42
Hex: 0xff

Testing

To run tests and verify the implementation, you can compile the main.c file provided with test cases:

gcc -Wall -Wextra -Werror -L. -lftprintf main.c -o test_ftprintf
./test_ftprintf

Project Structure

  • ft_printf.h: Header file containing function prototypes and macros.
  • ft_printf.c: The main ft_printf function implementation.
  • parsing.c: Functions for parsing format specifiers.
  • utils.c: Utility functions used by ft_printf.
  • Makefile: Makefile to build the library.

About

The goal of this project is pretty straightforward. Recode printf(). using a variable number of arguments.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published