Skip to content

vjan-nie/ft_printf

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ft_printf

A custom implementation of the standard C printf function, compiled as a static library that can be reused in other projects.

Features

This library implements the ft_printf function with support for the following format specifiers:

  • %c - Character
  • %s - String
  • %d / %i - Integer (decimal)
  • %u - Unsigned integer
  • %x / %X - Hexadecimal (lowercase/uppercase)
  • %p - Pointer address

Building the Library

To compile the library:

make

This will create ftprintf.a - a static library file containing all the compiled code.

To clean up object files:

make clean

To remove everything (object files and library):

make fclean

To rebuild from scratch:

make re

How to Use in Other Projects

Method 1: Direct Compilation (Simple Projects)

Copy the library and header to your project, then compile together:

cc -Wall -Wextra -Werror -I/path/to/ft_printf/include your_file.c /path/to/ft_printf/ftprintf.a -o your_program

Method 2: Using a Makefile (Recommended)

In your project's Makefile, include the ft_printf library:

# Variables
FT_PRINTF_PATH = /path/to/ft_printf
FT_PRINTF_LIB = $(FT_PRINTF_PATH)/ftprintf.a

# Compilation flags
CFLAGS = -Wall -Wextra -Werror -I$(FT_PRINTF_PATH)/include

# Your program
your_program: your_file.o $(FT_PRINTF_LIB)
	cc $(CFLAGS) your_file.o $(FT_PRINTF_LIB) -o your_program

your_file.o: your_file.c
	cc $(CFLAGS) -c your_file.c -o your_file.o

Method 3: Copy to Your Project (Standalone)

  1. Copy the entire ft_printf directory into your project
  2. In your Makefile, add:
CFLAGS += -I./ft_printf/include
LIBS = ./ft_printf/ftprintf.a

your_program: your_file.o $(LIBS)
	cc $(CFLAGS) your_file.o $(LIBS) -o your_program

Usage Example

#include "ft_printf.h"

int main(void)
{
    ft_printf("Hello, %s!\n", "World");
    ft_printf("Number: %d, Hex: %x\n", 42, 42);
    ft_printf("Pointer: %p\n", (void *)&main);
    
    return (0);
}

Project Structure

ft_printf/
├── Makefile              # Build configuration
├── include/
│   └── ft_printf.h       # Header file with ft_printf declaration
└── src/
    ├── ft_printf.c       # Main printf function
    ├── ft_strchr.c       # Character search utility
    ├── len_int_nbr.c     # Integer length calculator
    ├── write_char.c      # Character output handler
    ├── write_hex.c       # Hexadecimal output handler
    ├── write_int_nbr.c   # Integer output handler
    ├── write_ptr.c       # Pointer output handler
    ├── write_str.c       # String output handler
    └── write_uns_int_nbr.c # Unsigned integer output handler

Notes

  • The library is compiled with -Wall -Wextra -Werror flags for strict compilation standards
  • Always include the -I./include flag (or appropriate path) when compiling code that uses ft_printf
  • The library creates object files (*.o) which are cleaned with make clean

About

My own implementation of printf function in C

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors