Skip to content

Latest commit

 

History

31 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Custom Printf Fuction

This project implements a simplified version of the standard C library function printf using C programming language. The function _printf supports formatting options for characters (%c), strings (%s), and the percent symbol (%%) and integers (%d and %i). If an unsupported format specifier is encountered, the specifier itself is printed.

Features:

Specifiers Description
'%c' Print a single character
'%s' Print a string of characters
'%%' Print a percentage symbol
%i & %d print a nomber int
  • Unsupported Format Specifiers:

    • Prints the specifier as is.
  • Additional Functionality:

    • Handles NULL strings by printing "(null)".

Files:

  • main.h: Header file containing function declarations and necessary includes.
  • main.c Source file containing the implementation of _printf and auxiliary functions.
  • README.md This file, providing an overview of the project and usage instructions.

usage:

  • Compilation:

gcc -Wall -Werror -Wextra -pedantic -std=gnu89 -Wno-format *.c
  • Example Usage:

#include "main.h"
#include <stdio.h>

int main(void)
{
    int len;
    char ch = 'A';
    char *str = "Hello, world!";

    len = _printf("Let's print a character: %c\n", ch);
    _printf("Let's print a string: %s\n", str);
    _printf("Let's print the percent symbol: %%\n");
    _printf("Number of characters printed: %d\n", len);
    return (0);
}
  • Expected Output:

Let's print a character: A
Let's print a string: Hello, world!
Let's print the percent symbol: %
Number of characters printed: 47

Function Details

  • printf(const char *format, ...)

    • Main function that mimics printf. Takes a format string (format) and variable arguments (...). Iterates through the format string, printing characters directly unless it encounters a %, in which case it handles the specified format.
  • print_string(char *str, int *contador)

    • _uxiliary function used by printf to print strings. If str is NULL, it prints "(null)".
  • print_default(const char *format, int *i, int *counter)_

    • Handles the default case for unsupported format specifiers.
  • void print_numero(int n, int *contador)

    • This function prints an integer recursively. Handles negative numbers and updates the printed character counter
  • strlen(const char *s)

    • Calculates the length of the string 's'.
  • putchar(char c)

    • Writes the character c to the standard output.

😲 Antes y Después

Antes de usar Mi codigo_

Antes

_Después de usar Mi codigo:

Después

## 🤓 Datos Curiosos
  • ¿Sabías que...? Este proyecto usa más café que código.

https://github.com/maytepioli

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages