Coder Social home page Coder Social logo

printf's Introduction

Printf

Development repo for 42cursus' ft_printf project
For further information about 42cursus and its projects, please refer to Printf.


🗣️ About

This project is pretty straight forward. You will recode printf. Hopefully you will be able to reuse it in future project without the fear of being flagged as a cheater. You will mainly learn how to use variadic arguments.

For detailed information, refer to the subject of this project.

🚀 TLDR: this project consists of coding a library that contains a simplified version (more
information below) of the printf function.

Mandatory

  • format specifiers - cspdiuxX%
  • flags - -0.* and minimum field width with all conversions

Bonus

  • format specifiers - nfge (one or more)
  • flags - l ll h hh (one or more) and # + (all)

📑 Index

@root

@/ft_printf/

Note: files contain both mandatory and all bonus requirements.

Functions in ft_printf.c

  • ft_printf (and auxiliary static functions) - Initialization function: start/end variadic arguments functions <stdarg.h>; in between that, goes through the input string printing plain characters or collecting + treating format specifiers to the FORMAT SPECIFIER STRUCT thus printing each occurrance with the corresponding function.

Functions in ft_printf_flags.c

  • print_flags (and auxiliary static functions) - Prints each format specifier function's outputted string with formatting in accordance with the collected format specifiers.

Functions in ft_printf_csp_pct.c

The following functions output the input variable (collected by va_arg function) as a pointer to a string to be printed by the print_flags function.

  • print_spec_c - character (%c) type input variable;
  • print_spec_s - string (%s) type input variable;
  • print_spec_pct - percent (%%) character.

Functions in ft_printf_iduxo.c

The following functions output the input variable (collected by va_arg function) as a pointer to a string to be printed by the print_flags function.

  • print_spec_i_d_u - int (%i and %d) and unsigned int (%u)type input variables;
  • print_spec_x - lower (%x) and upper hexadecimal (%X) type input variables;
  • print_spec_o - octal (%o) type input variable;
  • print_spec_p - pointer (%p) type input variable.

Functions in ft_printf_f_g.c

The following functions output the input variable (collected by va_arg function) as a pointer to a string to be printed by the print_flags function.

  • print_spec_f_e_g - triage for float (%f), scientific notation (%e) and general format (%g) type input variables;
  • print_spec_f - float (%f) type input variable;
  • print_spec_g - general format (%g) type input variable.

Functions in ft_printf_f_g.c

The following functions output the input variable (collected by va_arg function) as a pointer to a string to be printed by the print_flags function.

  • print_spec_e - scientific notation (%e) type input variable.

Functions in ft_printf_utils.c

Basic Libc functions - Note: some were adapted and thus named with a suffix to indicate the nature of the customization.

  • ft_strlen - find length of string;
  • ft_strchr_01 - check the occurence of a character in a string;
  • ft_putchar_len - writes the input character to the output stream of stdout;
  • ft_putcstr_len - writes the input string to the output stream of stdout;

Functions in ft_printf_utils_2.c

Basic Libc functions - Note: some were adapted and thus named with a suffix to indicate the nature of the customization.

  • ft_strlcpy - copy string to another location;
  • ft_strlcat - concatenate strings;
  • ft_strdup - save a copy of a string (with malloc);
  • ft_strjoin - join two strings (with malloc);
  • ft_substr - extract a substring (with malloc).

Functions in ft_printf_utils_3.c

Basic Libc functions - Note: some were adapted and thus named with a suffix to indicate the nature of the customization.

  • ft_pow - returns the value of first argument raised to the power of second argument.
  • ft_ullitoa_base - allocates (with malloc) and returns a string representing the integer received as an argument according to the given base.
  • ft_fmod - returns the modulo of the float received as an argument.

Functions in ft_ftoa_rnd.c

  • ft_ftoa_rnd - allocates (with malloc) and returns a string representing the float received as an argument.

🛠️ Usage

Requirements

The library is written in C language and thus needs the gcc compiler and some standard C libraries to run.

Instructions

1. Compiling the library

To compile the library, run:

$ cd path/to/ft_printf && make

2. Using it in your code

To use the library functions in your code, simply include its header:

#include "ft_printf.h"

and, when compiling your code, add the required flags:

-lftprintf -L path/to/libftprintf.a -I path/to/ft_printf.h

Third-party testers

📌 Useful Links

printf's People

Contributors

lmoraesdev avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.