This project is an implementation of the printf function in the C programming language. The printf function is used to print formatted output to the console or terminal. This implementation follows the basic behavior and functionality of the standard printf function.
The printf function takes a format string and a variable number of arguments. The format string is a string of characters that specify how to format the output. The arguments are a list of values that are substituted into the format string.
This implementation of the printf function supports the following format specifiers:
Format specifier | Description |
---|---|
%c |
Character |
%s |
String |
%d |
Signed integer |
%i |
Signed integer |
%u |
Unsigned integer |
%x |
Unsigned integer (hexadecimal) |
%X |
Unsigned integer (uppercase hexadecimal) |
%p |
Pointer |
%% |
Print a percent sign |
To use the printf function, include the "printf.h" header file in your program. You can then call the printf function with a format string and the variables to be substituted into the format string.
Here is an example:
#include "printf.h" #include <stdio.h>
int main() { char c = 'H'; char* s = "ello"; int i = 42;
printf("%c%s %d\n", c, s, i);
return 0;
}
In this example, the format string "%c%s %d\n"
specifies that the character c
, the string s
, and the integer i
should be printed in order.
To test the printf implementation, a test suite has been included in the "test" directory. The test suite uses the Unity testing framework to run a series of tests on the printf function.
To run the test suite, first compile the "test_printf.c" file:
gcc -o test_printf test/test_printf.c src/printf.c
Then, run the compiled test executable:
./test_printf
The test output will be displayed in the console or terminal.
The aim of the project is to understand the concept of team work and therefore, demisifying the concept of printf
These are all the tasks of this project, the ones that are completed link to the corresponding files.
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 format.
- c : converts input into a character
- s : converts input into a string
- Handle the following conversion specifiers:
- d : converts input into a base 10 integer
- i : converts input into an integer
- Create a man page for your function
- Handle the following conversion specifiers:
- b : the unsigned int argument is converted to binary
- Handle the following conversion specifiers:
- u : converts the input into an unsigned integer
- o : converts the input into an octal number
- x : converts the input into a hexadecimal number
- X : converts the input into a hexadecimal number with capital letters
- Use a local buffer of 1024 chars in order to call write as little as possible.
- Handle the following custom conversion specifier:
- S : prints the string
- Non printable characters (0 < ASCII value < 32 or >= 127) are printed this way: \x, followed by the ASCII code value in hexadecimal (upper case - always 2 characters)
7. How is the world ruled and led to war? Diplomats lie to journalists and believe these lies when they see them in print
- Handle the following conversion specifier:
- p : int input is converted to a pointer address
- Handle the following flag characters for non-custom conversion specifiers:
- + : adds a + in front of signed positive numbers and a - in front of signed negative numbers
- space : same as +, but adds a space (is overwritten by +)
- # : adds a 0 in front of octal conversions that don't begin with one, and a 0x or 0X for x or X conversions
- Handle the following length modifiers for non-custom conversion specifiers:
- l : converts d, i, u, o, x, X conversions in short signed or unsigned ints
- h : converts d, i, u, o, x, X conversions in long signed or unsigned ints
- Handle the field width for non-custom conversion specifiers.
- Handle the precision for non-custom conversion specifiers.
- Handle the 0 flag character for non-custom conversion specifiers.
13. Every time that I wanted to give up, if I saw an interesting textile, print what ever, suddenly I would see a collection]
- Handle the - flag character for non-custom conversion specifiers.
- Handle the following custom conversion specifier:
- r : prints the reversed string
- Handle the following custom conversion specifier:
- R : prints the rot13'ed string
- All the above options work well together.