Giter VIP home page Giter VIP logo

ft_printf_1337's Introduction

42cursus' ft_printf

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

🗣️ About

The printf function (the name comes from “print formatted”) prints a string on the screen using a “format string” that includes the instructions to mix several strings and produce the final string to be printed on the screen.

printf("The value is %d\n", counter);

->The printf function (the name comes from “print formatted”) prints a string on the screen using a “format string” that includes the instructions to mix several strings and produce the final string to be printed on the screen

->The symbol “%” denotes the beginning of a format :
-d for int
-s for string
-c for caracter
-p for dress en hex
-I like d
-u int decimal unsigned
-x hex whit lowercase
-X hex with uppercase
-% sign percentage

->Deff btw %i and %d is that in scanf; 012 (d = 12) (i = 10)


Understanding size_t

The type size_t represents the maximum size any object can be in C. It is an unsigned integer since negative numbers do not make sense in this context. Its purpose is to provide a portable means of declaring a size consistent with the addressable area of memory available on a system. The size_t type is used as the return type for the sizeof operator and as the argument to many functions, including malloc and strlen, among others.

It is good practice to use size_t when declaring variables for sizes such
as the number of characters and array indexes. It should be used for
loop counters, indexing into arrays, and sometimes for pointer
arithmetic.




VARIADIC FUNCTION

-> A variable function is an undefined edge function.

->TYPEDEF VA_LIST:

* typedef struct {
*    unsigned int gp_offset;
*    unsigned int fp_offset;
*    void *overflow_arg_area;
*    void *reg_save_area;  
* } va_list[1];


The (va_start) macro initializes the structure as follows:
reg_save_area The element points to the start of the register save area


overflow_arg_area This pointer is used to fetch arguments passed on the stack. It is initialized with the address of the first argument passed on the stack, if any, 	and then always updated to point to the start of the next argument on the stack.

gp_offset The element holds the offset in bytes from reg_save_area to the place where the next available general purpose argument register is saved. In case all 	argument registers have been exhausted, it is set to the value 48 (6 * 8).

fp_offset The element holds the offset in bytes from reg_save_area to the place where the next available floating point argument register is saved. In case all 	argument registers have been exhausted, it is set to the value 304 (6 * 8 + 16 * 16).

->Sometimes, va_list is simply char*. Basically, ap represents an array of pointers to chars. When calling va_arg(ap, TYPE) it reads memory from address at which ap points, but it reads it as TYPE type. So, if you call it with int it will read 4 bytes and convert it to int type

->there is no way to compute the length of a (va_list)

-> #include <stdarg.h> Cette librairie permet de coder des fonctions à nombre variable de paramètres (d'arguments). L'exemple le plus connu de fonction à nombre variable de paramètres est certainement la fonction printf

-> macros : Macro in C programming is known as the piece of code defined with the help of the #define directive. Macros in C are very useful at multiple places to replace the piece of code with a single value of the macro. —————————————————————

  1. #define - Preprocessor Directive
  2. PI - Macro Name
  3. 3.14 - Macro Value

->Preprocessor Directive: Preprocessor directives are lines included in a program that begin with the character #, which make them different from a typical source code text.

Types of macros in Nutshell :

Sr.No. |Macro Name |Description 1 |Object Like |Value or code segment gets replaced with macro name 2 |Function Like |The macro which takes an argument and acts as a function 3 |Chain Like |The macro inside another macro

-> the macros available for working with va_list are : ->va_strat : start using the list. The va_start() macro initializes ap for subsequent use by va_arg() and va_end(), and must be called first

->va_arg.   : get the next argument.
	The va_arg() macro expands to an expression that has the type and value of the next argument in the call.

->va_end    : stop using the va_list.
 Each invocation of va_start() must be matched by a corresponding invocation of va_end() in the same function.
	After the call va_end(ap) the variable ap is undefined.

->va_copy   : copy the va_list.
 The va_copy() macro copies the (previously initialized) variable argument list src to dest.

📌 Useful Links

ft_printf_1337's People

Contributors

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