So_long/ft_printf_fd/Readme.md

48 lines
1.5 KiB
Markdown

# ft_printf_fd
Your own implementation of the printf function with file descriptor support.
## 💡 About
The ft_printf_fd project is an extension of ft_printf that allows writing to any file descriptor. You will learn about file descriptors, variadic arguments and formatted output conversion. This project enhances the original printf functionality by adding the ability to choose the output destination.
## 🛠️ Supported Conversions
The function handles the following conversions:
* `%c` - Single character
* `%s` - String
* `%p` - Pointer address
* `%d` - Decimal (base 10) integer
* `%i` - Integer in base 10
* `%u` - Unsigned decimal (base 10) integer
* `%x` - Hexadecimal (base 16) integer lowercase
* `%X` - Hexadecimal (base 16) integer uppercase
* `%%` - Percentage sign
## 📋 Usage
```c
#include "ft_printf_fd.h"
int main(void)
{
// Write to stdout (fd 1)
ft_printf_fd(1, "Hello %s!\n", "world");
// Write to stderr (fd 2)
ft_printf_fd(2, "Error: %d\n", 42);
// Write to a file
int fd = open("output.txt", O_WRONLY | O_CREAT, 0644);
ft_printf_fd(fd, "Number: %d\n", 42);
close(fd);
return (0);
}
```
## ⚠️ Function Prototype
```c
int ft_printf_fd(int fd, const char *format, ...);
```
Returns the number of characters printed (excluding the null byte used to end output to strings).
## 📊 Expected Output
The function should work exactly like the original printf, handling all the specified conversions correctly, but writing to the specified file descriptor instead of stdout.