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.
| Specifiers | Description |
|---|---|
| '%c' | Print a single character |
| '%s' | Print a string of characters |
| '%%' | Print a percentage symbol |
| %i & %d | print a nomber int |
-
- Prints the specifier as is.
-
- Handles NULL strings by printing "(null)".
- 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.
gcc -Wall -Werror -Wextra -pedantic -std=gnu89 -Wno-format *.c
#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);
}
Let's print a character: A
Let's print a string: Hello, world!
Let's print the percent symbol: %
Number of characters printed: 47
-
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 de usar Mi codigo_
_Después de usar Mi codigo:
## 🤓 Datos Curiosos
- ¿Sabías que...? Este proyecto usa más café que código. ☕

