The project, _printf is the first major project that is built in the holberton school, is about building a function as similar as possible to the original function present in the standard library of programming language C, this is a challenge of some difficulty since the original function behaves in very specific ways in certain cases.
This project was built by Alejandro López and Juan Marcos Cabezas
👤 Alejandro López
- Twitter: @alejolo311
- Github: @alejolo311
👤 Juan Marcos Cabezas
- Twitter: @juanmarcab
- Github: @juanmarcoscabezas
- The main function uses structures to call the function corresponding to the case, this allows greater code scalability.
- As in the original printf, the function has a buffer that stores and prints the output strings every 1024 bytes.
- Just like the original printf, the returns of our function are the number of characters printed, when the input is incorrect the return is error -1
- compile on Ubuntu 14.04 LTS
- compile with gcc 4.8.4
$ gcc -Wall -Werror -Wextra -pedantic *.c
#include <limits.h>
#include <stdio.h>
#include "holberton.h"
/**
* main - Entry point
*
* Return: Always 0
*/
int main(void)
{
int len;
int len2;
unsigned int ui;
void *addr;
len = _printf("Let's try to printf a simple sentence.\n");
len2 = printf("Let's try to printf a simple sentence.\n");
ui = (unsigned int)INT_MAX + 1024;
addr = (void *)0x7ffe637541f0;
_printf("Length:[%d, %i]\n", len, len);
printf("Length:[%d, %i]\n", len2, len2);
_printf("Negative:[%d]\n", -762534);
printf("Negative:[%d]\n", -762534);
_printf("Unsigned:[%u]\n", ui);
printf("Unsigned:[%u]\n", ui);
_printf("Unsigned octal:[%o]\n", ui);
printf("Unsigned octal:[%o]\n", ui);
_printf("Unsigned hexadecimal:[%x, %X]\n", ui, ui);
printf("Unsigned hexadecimal:[%x, %X]\n", ui, ui);
_printf("Character:[%c]\n", 'H');
printf("Character:[%c]\n", 'H');
_printf("String:[%s]\n", "I am a string !");
printf("String:[%s]\n", "I am a string !");
_printf("Address:[%p]\n", addr);
printf("Address:[%p]\n", addr);
len = _printf("Percent:[%%]\n");
len2 = printf("Percent:[%%]\n");
_printf("Len:[%d]\n", len);
printf("Len:[%d]\n", len2);
_printf("Unknown:[%r]\n");
printf("Unknown:[%r]\n");
return (0);
}| Specifier | Function name |
|---|---|
| %c | print_char() |
| %s | print_string() |
| %% | print_percen() |
- %c is about being able to print the individual characters that were passed as a parameter to the function.
- _printf("%c", NULL);
- _printf("%c", 'A');
- _printf("%c", 'A');
- %s is about being able to print strings, which are received as parameters to eh function.
- _printf("%s", "holberton");
- _printf("%ss", "holberton");
- _printf("%s", "");
- _printf("%s");
%%
- %% is about being able to print the the char % because being the indefinifier of printf specifiers could generate conflicts at the time of printing.
- _printf("%%");
| Specifier | Function name |
|---|---|
| %d | print_d() |
| %i | print_i() |
- %d is about being able to print the integers that can be handled in the int variable, the smallest number is -2147483648 and the max is 2147483647
- _printf("%d",-2147483648);
- _printf("%d", 2147483647);
- %i is about being able to print the integers that can be handled in the int variable, the smallest number is -2147483648 and the max is 2147483647
- _printf("%i",-2147483648);
- _printf("%i", 2147483647);
- The Manual.
- Task 1
- Task 2
- Task 3
- Task 4
- Task 5
- Task 6
- Task 7
- Task 8
- Task 9
- Task 10
- Task 11
- Task 12
- Task 13
- Task 14
- Task 15
- task 16
- printf(NULL);
- printf("%");