Skip to content

hbuivu/42_ft_printf

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 

Repository files navigation

ft_printf

Implementing my own printf in C

Function

int ft_printf(const char *str, ...);

Capabilities

  • %c Prints a single character.
  • %s Prints a string (as defined by the common C convention).
  • %p The void * pointer argument has to be printed in hexadecimal format.
  • %d Prints a decimal (base 10) number.
  • %i Prints an integer in base 10.
  • %u Prints an unsigned decimal (base 10) number.
  • %x Prints a number in hexadecimal (base 16) lowercase format.
  • %X Prints a number in hexadecimal (base 16) uppercase format.
  • %% Prints a percent sign

Pseudo Code

  • Declare a va_list ptr
  • Iterate through the first string
    • If we see % + format_char, we will access the next argument using va_arg and process it according to what the format_char is
      ex: as we iterate through the string, we come across %d. The next va_arg is "123". We will use ft_putnbr to print out the argument and count the approriate chars being printed
    • Otherwise we print the character
    • Don't forget to count the characters being printed out!
  • va_end and return count

Concepts

Variadic functions: functions that can allow a variable number of arguments

  1. va_list: declare this pointer type to use in the below functions
  2. va_start: allow access to varaidac function arguments
    va_start(va_list ap, argN) va_list is the pointer to the last fixed arg in the variadic function
    argN is the last fixed argument n the variadic function
  3. va_arg: access next argument
    va_arg(va_list ap, type) type is the type of of data that va_arg should expect
  4. va_copy: make copy of function args
    va_copy(va_list dest, va_list src)
  5. va_end: end traversal of function arguments va_end(va_list ap)

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors