Coder Social home page Coder Social logo

pgomez-a / ft_printf Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 107 KB

The definition of this project is simple: replicate the workings of the famous printf function.

Home Page: https://www.linkedin.com/in/pgomez-a/

License: MIT License

Makefile 3.79% C 96.21%
unix logic rigor algorithms-and-ai

ft_printf's Introduction

ft_printf

ft_printf

If you want to learn more about IT topics, I invite you to join my Patreon channel and visit my website: IA Notes

The definition of this project is simple: replicate the workings of the famous printf function. Thanks to this, it won't be necessary for us to continue using ft_putchar_fd and ft_putstr_fd every time we want to display a character, a string of characters or a number on the screen.

MAIN OBJECTIVES

The main objective that we want to achieve with this project is to be able to define functions that receive a variable number of arguments. Up to now, every time we define the prototype of a function, we establish a series of mandatory (fixed) parameters that must be entered when calling the function. However, we can see that a function like printf can receive as many parameters as the user specifies. So how is it able to do this? The simple answer is found in the use of the <stdarg.h> library.

HOW TO USE FT_PRINTF?

  1. Clone ft_printf repository:

    git clone https://github.com/pgomez-a/ft_printf.git && cd ft_printf
    
  2. Run make to create the static library libftprintf.a:

    make
    
  3. Now, you can move the library wherever your project is, but the include of your main project should be the path of the ft_printf repository:

    /* Suppose main.c is in the ft_printf repository */
    
    #include "ft_printf.h"
    
    int main(void)
    {
    
  4. Compile your program with the new library:

    gcc main.c -L. -lftprintf
    

<stdarg.h>

This library will allow us to work with the use of functions capable of receiving a variable number of arguments. To do this, you will declare a new type of variable and three different macros:

  • va_list --> variable
  • va_start --> macro
  • va_arg --> macro
  • va_end --> macro

If you want to know more about how to use each of these macros, you already know the answer: RTFM. However, if you want to ask me a question or discuss about some functionality of this library, you can do it through the contact information of my README: I'll be happy to talk to you !!

RETURN VALUES

Although the use of printf consists of displaying a format string on the standard output (stdin;), it also has a return value, since it is a function of type int. This return will be the number of characters you have printed on the screen, and not the number of characters in the format string.

EXAMPLES OF USE

Some examples of the use of our ft_printf, comparing it with the real printf and being ft = output_printf and sy = output_ft_printf:

Regular case main Regular example main

Regular case main Regular example main

However, there are some particular cases that we must take into account, both when working with the computer memory and when making a correct cast:

Special case main.c Special case example

ft_printf's People

Contributors

pgomez-a avatar

Stargazers

 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.