|
1 | 1 |
|
2 |
| -# Exercise 7-3 |
| 2 | +## Exercise 7-3 — The C Programming Language, 2nd Edition |
3 | 3 |
|
4 |
| -## Task |
| 4 | +Revise the `minprintf` function from Chapter 7 to support more of the formatting capabilities of the standard `printf` function. The original `minprintf` handles only a limited set of conversion specifiers (like `%d`, `%f`, `%s`, etc.) and minimal flag support. |
5 | 5 |
|
6 |
| -Revise `minprintf` to handle more of the other facilities of `printf`. |
| 6 | +Your task is to improve it so it can interpret and pass along additional format specifiers and flags, such as: |
7 | 7 |
|
8 |
| -## Objective |
| 8 | +- Field width and precision (e.g., `%6.2f`) |
| 9 | +- Left-justification (`%-d`) |
| 10 | +- Zero-padding (`%05d`) |
| 11 | +- Alternate form (`%#x`, `%#o`) |
| 12 | +- Signs (`%+d`, `% d`) |
9 | 13 |
|
10 |
| -Extend the functionality of the `minprintf` function from Chapter 7 of *The C Programming Language (K&R)* to support more format specifiers and flags, closer to the standard `printf` behavior. |
| 14 | +### Notes |
11 | 15 |
|
12 |
| -## Requirements |
| 16 | +- The goal is not to reimplement `printf` but to parse the format string more fully and correctly pass the format and corresponding argument to `printf`. |
| 17 | +- Use <stdarg.h> for handling the variable arguments, as shown in the original `minprintf`. |
| 18 | +- Test with a variety of format strings to ensure your implementation works correctly. |
13 | 19 |
|
14 |
| -- Add support for additional format specifiers such as: |
15 |
| - - `%o`, `%x`, `%X`, `%u`, `%c`, `%e`, `%g`, etc. |
16 |
| -- Handle flags like: |
17 |
| - - `-` (left justify), `+` (sign), `0` (zero-padding), `#` (alternate form), and space. |
18 |
| -- Optionally support field width and precision (e.g., `%10.2f`). |
| 20 | +### Deliverables |
19 | 21 |
|
20 |
| -## Notes |
21 |
| - |
22 |
| -This task is meant to deepen understanding of variadic functions, format parsing, and output formatting in C. |
| 22 | +- An updated `minprintf` function in C |
| 23 | +- Example usage that demonstrates the supported features |
0 commit comments