Skip to content

Commit 5bfc4c9

Browse files
committed
docs(readme): enhance structure and clarity
1 parent 41c5a28 commit 5bfc4c9

1 file changed

Lines changed: 42 additions & 16 deletions

File tree

README.md

Lines changed: 42 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -62,45 +62,66 @@
6262
</header>
6363

6464

65-
A custom implementation of the C standard library's `printf` function. This project is part of the 42 school curriculum and aims to replicate the original `printf` behavior, including handling various format specifiers, flags, and arguments.
65+
A custom implementation of the C standard library's `printf` function. This project is part of the 42 school curriculum and recodes the original `printf` behavior, providing a lightweight and portable way to format and print data.
6666

6767
## Features
6868

69-
- **Handles standard format specifiers**: `c`, `s`, `p`, `d`, `i`, `u`, `x`, `X`, and `%%`.
70-
- **Implements bonus flags**: `-` (left-justify), `0` (zero-padding), `.` (precision), and `#` (alternate form for `x`/`X`).
71-
- **Supports field width**: Controls the minimum number of characters printed, including dynamic width using `*`.
69+
This implementation of `ft_printf` supports the following format specifiers, flags, and features:
70+
71+
#### Conversion Specifiers
72+
73+
| Specifier | Output |
74+
| :---: | --- |
75+
| `%c` | A single character. |
76+
| `%s` | A string of characters. |
77+
| `%p` | The memory address of a pointer, in hexadecimal format. |
78+
| `%d` | A signed decimal integer. |
79+
| `%i` | A signed decimal integer. |
80+
| `%u` | An unsigned decimal integer. |
81+
| `%x` | An unsigned hexadecimal integer (lowercase). |
82+
| `%X` | An unsigned hexadecimal integer (uppercase). |
83+
| `%%` | A literal percent sign (`%`). |
84+
85+
#### Flags and Modifiers
86+
87+
- **`-`**: Left-justify the output within the field width.
88+
- **`0`**: Zero-pad the output instead of using spaces.
89+
- **`.`**: Specifies precision for strings and integers.
90+
- **`#`**: Alternate form; prepends `0x` or `0X` for hexadecimal conversions.
91+
- **Width**: Specifies a minimum field width for the output.
92+
- **`*`**: Use the next argument as the field width.
7293

7394
## Getting Started
7495

7596
### Prerequisites
7697

7798
- A C compiler (e.g., `gcc` or `clang`)
78-
- `make` utility
99+
- `make` build automation tool
79100

80-
### Installation & Compilation
101+
### Building the Library
81102

82103
1. **Clone the repository:**
83104
```sh
84105
git clone https://github.com/jdecorte-be/ft-printf.git
85106
cd ft-printf
86107
```
87108

88-
2. **Compile the library:**
89-
Run `make` to compile the source files and create the static library `libftprintf.a`.
109+
2. **Compile the source files:**
110+
Run `make` to compile the project and create the static library `libftprintf.a`.
90111
```sh
91112
make
92113
```
93114

94115
## Usage
95116

96-
To use `ft_printf` in your own project:
117+
To use `ft_printf` in your C project, include the header and link against the compiled library.
97118

98-
1. Include the header file `ft_printf.h` in your C source files.
99-
2. Compile your project and link it with the `libftprintf.a` library.
119+
1. Include the header file in your source code: `#include "ft_printf.h"`.
120+
2. Compile your project, linking the `libftprintf.a` library.
100121

101122
### Example
102123

103-
Here is a simple `main.c` file demonstrating the function's usage:
124+
Here is a simple `main.c` demonstrating the function's usage:
104125
105126
```c
106127
#include "includes/ft_printf.h"
@@ -124,15 +145,19 @@ int main(void)
124145
}
125146
```
126147
127-
**Compile and run the example:**
148+
#### Compiling and Running
149+
150+
First, ensure `libftprintf.a` has been created by running `make`. Then, compile your `main.c` with the library:
128151
129152
```sh
130-
# First, ensure libftprintf.a has been created with `make`
131-
gcc main.c libftprintf.a -o example
153+
# Compile the main program and link the library
154+
gcc main.c -L. -lftprintf -Iincludes -o example
155+
156+
# Run the executable
132157
./example
133158
```
134159
135-
**Expected Output:**
160+
#### Expected Output
136161
137162
```
138163
--- Testing ft_printf ---
@@ -143,6 +168,7 @@ Pointer address: 0x7ff7bfeff22c
143168
This line has 31 characters.
144169
The previous line printed 31 characters.
145170
```
171+
*Note: The pointer address will vary on your system.*
146172
147173
## License
148174

0 commit comments

Comments
 (0)