Skip to content

serena-zhu/ft_printf

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

131 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Ft_printf is a variadic function that recreates much of printf's functionalities.

Contents

Language & Functions Used | Installation & Usage | Format Specification Fields

The ft_printf function is written in C, using only the following functions from the standard C libraries:

  • write
  • stdarg

↥ back to top

Step 1 - clone the repo at the root of your project folder

$ git clone https://github.com/serena-zhu/ft_printf.git

Step 2 - compile library

$ make

The Makefile will compile a static library called libftprintf.a, which can be compiled with your program source files as follows:

$ gcc -Wall -Wextra -Werror -o program_name source_file -L ./ft_printf -lftprintf

↥ back to top

Flags

  • #
  • 0
  • -
  • +
  • space
  • '

Minimum Field Width

  • # [given as any hardcoded number e.g. ft_printf("%4d\n", number);]
  • * [given as a variable e.g. ft_printf("%*d\n", 4, number); Note: if a negative number is provided, the absolute value will be used and a '-' flag will be added]

Precision

  • .# [given as any hardcoded number e.g. ft_printf("%.2f\n", number);]
  • .* [given as a variable e.g. ft_printf("%.*f\n", 2, number);]

Length modifiers

  • hh
  • h
  • l
  • ll
  • j
  • z
  • L

Conversion Specifiers

  • s, S
  • p
  • d, D, i
  • o, O
  • u, U
  • x, X
  • c, C
  • e, E
  • f, F
  • g, G
  • n

Color Management

This function includes a color management functionality that is different from printf.

To use: specify colors in between {} and end color with {eoc}. If the closing bracket } is missing, the opening bracket { and the texts that follow will be printed to standard output.

Example:

$ cat main.c

#include "ft_printf.h"

int	main(void)
{
	ft_printf("This will be{red} red text {eoc}and now the text color is back to default.\n");
	return (0);
}
$ gcc -Wall -Wextra -Werror main.c -L ./ft_printf -lftprintf
$ ./a.out

color_output

Supported colors are:

  • black | red | green | yellow | blue | magenta | cyan | white | gray
  • light red | light green | light yellow | light blue | light magenta | light cyan

↥ back to top

About

Printf function recoded

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors