CLICK TO ENLARGE 😇
DescriptionObjectives
Requirements
Instructions
Tech stack
Files description
Installation and how to use
Thanks
Authors
This project is a recreation of the C library function printf, developed as part of the Holberton School curriculum.
It aims to handle formatted output to the standard output stream using only low-level system calls, while respecting strict constraints.
|
At the end of this project, I should be able to explain to anyone, without the help of Google:
- How variadic functions work in C.
- How the
va_list,va_start,va_arg, andva_endmacros are used. - The difference between low-level and high-level output functions.
- How to structure a large C project with multiple files and headers.
- How to manage group projects and pair programming effectively.
- How to write and use a custom
manpage.
- My programs and functions will be compiled with
gccusing the flags-Wall,-Werror,-Wextra,-pedanticand-std=gnu89. - All my files should end with a new line.
- My code should use the Betty style. It will be checked using betty-style.pl and betty-doc.pl.
- I am not allowed to use global variables.
- No more than 5 functions per file.
- The prototypes of all my functions should be included in my header file called
main.h. - All my header files should be include guarded.
List of allowed functions and system calls.
write(man 2 write)malloc(man 3 malloc)free(man 3 free)va_start(man 3 va_start)va_end(man 3 va_end)va_copy(man 3 va_copy)va_arg(man 3 va_arg)
0. I'm not going anywhere. You can print that wherever you want to. I'm here and I'm a Spur for life
Write a function that produces output according to a format.
- Prototype:
int _printf(const char *format, ...);. - Returns: the number of characters printed (excluding the null byte used to end output to strings).
- Write output to stdout, the standard output stream.
formatis a character string. The format string is composed of zero or more directives. Seeman 3 printffor more detail. You need to handle the following conversion specifiers:cs%
- You don’t have to reproduce the buffer handling of the C library
printffunction. - You don’t have to handle the flag characters.
- You don’t have to handle field width.
- You don’t have to handle precision.
- You don’t have to handle the length modifiers.
Repo:
- GitHub repository:
holbertonschool-printf.
1. Education is when you read the fine print. Experience is what you get if you don't
Handle the following conversion specifiers:
di- You don’t have to handle the flag characters.
- You don’t have to handle field width.
- You don’t have to handle precision.
- You don’t have to handle the length modifiers.
Repo:
- GitHub repository:
holbertonschool-printf.
2. Just because it's in print doesn't mean it's the gospel
Create a man page for your function.
Repo:
- GitHub repository:
holbertonschool-printf.
3. With a face like mine, I do better in print
Handle the following custom conversion specifiers:
b: the unsigned int argument is converted to binary.
alex@ubuntu:~/c/printf$ cat main.c
#include "main.h"
/**
* main - Entry point
*
* Return: Always 0
*/
int main(void)
{
_printf("%b\n", 98);
return (0);
}
alex@ubuntu:~/c/printf$ gcc -Wall -Wextra -Werror -pedantic -std=gnu89 main.c
alex@ubuntu:~/c/printf$ ./a.out
1100010
alex@ubuntu:~/c/printf$Repo:
- GitHub repository:
holbertonschool-printf.
4. What one has not experienced, one will never understand in print
Handle the following conversion specifiers:
uoxX- You don’t have to handle the flag characters.
- You don’t have to handle field width.
- You don’t have to handle precision.
- You don’t have to handle the length modifiers.
Repo:
- GitHub repository:
holbertonschool-printf.
| FILES | DESCRIPTION |
|---|---|
assets |
Contains the resources required for the repository. |
main.c |
Test file showcasing _printf with various format specifiers. |
main.h |
Contains the main structure and the function prototypes. |
_printf.c |
Contains my main _printf function. |
specifiers_handler.c |
Contains the function for associating a specifier with the corresponding function. |
mandatory_functions.c |
Contains all my mandatory print functions. |
advanced_functions.c |
Contains all my advanced print functions. |
man_3_printf |
man page of the _printf function. |
README.md |
The README file you are currently reading 😉. |
main.cis provided for demonstration purposes only and is not part of the mandatory project files.
- Clone this repository:
- Open your preferred Terminal.
- Navigate to the directory where you want to clone the repository.
- Run the following command:
git clone https://github.com/fchavonet/holbertonschool-printf.git-
Open the repository you've just cloned.
-
Compile the source code:
gcc -Wall -Werror -Wextra -pedantic -std=gnu89 -Wno-format *.c -o test_printfA
main.ctest file is provided for demonstration purposes. You can modify it to try different format specifiers supported by_printf(see table below).
| SPECIFIERS | DESCRIPTION |
|---|---|
%c |
Print a single character. |
%s |
Print a null-terminated string. |
%% |
Print a literal '%' character. |
%d |
Print a signed decimal number. |
%i |
Print a signed integer. |
%b |
Print an integer in binary (custom). |
%u |
Print an unsigned decimal number. |
%o |
Print an integer in octal. |
- Run the program:
./test_printfExpected output:
A
The cake is a lie!
%
42 is the answer to life, the universe, and everything...
42
-42
The number 42 converted into binary is 101010
4294967295
The number 42 converted into octal is 52- Open the MAN page:
man ./man_3_printfIf the file does not open, you may need to grant execution permissions first.
- A big thank you to all my Holberton School peers for their help and support throughout this project.
Fabien CHAVONET
- GitHub: @fchavonet
