Giter VIP home page Giter VIP logo

printf's Introduction

image

Project files

main.h : Include all function prototypes and structure of specifiers

_printf.c : This code defines a function called _printf, which takes a format string and optional arguments and produces output according to the format string. The function iterates over the format string, parsing it for format specifiers (beginning with a '%') and handling each one according to its type. It uses a buffer to store the output and writes to the standard output when the buffer is full or when the iteration is complete. The function returns the total number of characters printed.

flags.c : This code parses a formatted string (passed as the format parameter) and extract any active flags used in the string. The function starts by initializing flags to zero and setting curr_i to the value pointed to by i plus one.

get_precision.c : This code defines a function named get_precision that takes three parameters: a const char* format, an int* i, and a va_list list. The function calculates the precision for printing by parsing the format string starting at position *i and returns it as an int. The precision is determined by looking for a period '.' character in the format string, followed by either a '*' character indicating a variable argument passed through va_list list, or by a series of digits representing the precision. The function updates the value of *i to the last position it read from the format string.

get_size : The purpose of the function is to determine the size to cast an argument based on the format specifier in the format string. It looks for the characters 'l' or 'h' immediately after the format specifier and sets the size accordingly.

get_width.c : Calculates the width for printing by iterating over the format string, extracting the width if it is specified explicitly in the format string, or extracting the width from the list of arguments if it is specified using a * in the format string. Finally, it updates the i value to skip over the width specifier in the format string and returns the extracted width value.

handle_print.c : Handles printing of different types of arguments in a formatted string. It takes in several parameters such as the formatted string to print (fmt), an index pointer (ind), a list of arguments to print (list), a buffer to store the printed output (buffer), active flags (flags), width specification (width), precision specification (precision), and size specifier (size).

handlers.c : This is a program that includes several functions to handle printing of characters, numbers, and unsigned numbers with specific format specifiers. The program contains comments describing each function and its parameters, as well as its expected return value.

print_functions.c : This code defines a set of functions that can be used to print formatted output to the console. It includes functions to print characters, strings, integers, and binary numbers, as well as a function to print a percent sign.

utils.c : This is a C code file that includes a set of functions. Here is a brief explanation of each function:

  1. is_printable(char c): This function takes a character c and evaluates if it is printable. It returns 1 if c is printable and 0 otherwise.

  2. append_hexa_code(char ascii_code, char buffer[], int i): This function appends the ASCII code of a character ascii_code to a buffer buffer in hexadecimal format starting at index i. The function returns the value 3.

  3. is_digit(char c): This function takes a character c and verifies if it is a digit. It returns 1 if c is a digit and 0 otherwise.

  4. convert_size_number(long int num, int size): This function takes a number num and casts it to the specified size size. If size is S_LONG, it returns the num as is. If size is S_SHORT, it casts num to a short. Otherwise, it casts num to an int.

  5. convert_size_unsgnd(unsigned long int num, int size): This function takes an unsigned number num and casts it to the specified size size. If size is S_LONG, it returns the num as is. If size is S_SHORT, it casts num to an unsigned short. Otherwise, it casts num to an unsigned int.

The file includes the header file main.h. The header file likely includes declarations for these functions and any necessary libraries.

printf's People

Contributors

rafmury avatar ridhwan497 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.