Giter Club home page Giter Club logo

my_printf's Introduction

my_printf

my_printf (or print function in C) takes a formatting string and a format variable as input and outputs strings to console while converting input variables to strings. My_printf takes multiple arguments and these functions are called variable length argument functions or vararg functions. The user supplies a string and input arguments. My_printf creates an internal buffer for constructing the output string. My_printf then iterates through each characters of the user string, counts the character, and copies the character to the output string. My_printf only stops at "%". "%" means that there is an argument to format.

DETAILS ON FORMATTING

To sum, my_printf operates by scanning the format string from left to right.
Each character from the format string is appended to the result string unless it is a percent sign.
If the character is a % then it is not copied to the result string.
Instead, the characters following the % character are treated as a conversion specifier.
The conversion specifier controls the conversion of the next successive arg to a particular format and the result is appended to the result string in place of the conversion specifier. The conversion specifier simply determines what kind of conversion to perform. The following conversion characters are supported by this program:

  • Integer arguments are converted to signed decimal (d), unsigned octal (o), unsigned decimal (u), or unsigned hexadecimal (x).
  • Character argument (c): individual characters are directly copied to output.
  • String argument (s): character arrays are written up to (but not including) a terminating NUL character.
  • Pointer argument (p): the pointer argument is printed in hexadecimal.
  • All characters and arguments are counted, and that is the return value of my_printf.

Variadic types & macros (a brief overview) Type Defined in header file <stdarg.h>

va_list (type) holds the information needed by macros va_start, va_arg, va_end, and va_copy

va_start (macro) start of iterations in the variadic function arguments

va_arg (macro) get the next variadic function argument

va_copy (macro) makes a copy of the variadic function arguments (Available only in C99)

va_end (macro) ends of iteration in the variadic function arguments


To test this program you can run:

make print

my_printf's People

Contributors

felipemelendez 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.