Printf is a group project assignment of two, this project is aimed towards cloning the printf function in c programming, the project is in stages and each stage define and adds more features to our custom printf. The custom function will be named _printf. Following below are the names of the project contributors.
- What is Variadic Functions?
Variadic function takes indefinite size arity and a variable number of arguments as a parameter. Situations that you do not know how many parameters pass the function.
- what is ellipses (...)?
The ellipsis (...) is part of the C language and indicates that there are 0 or more optional arguments.
- What is va_list?
a complete object type suitable for holding the information needed by the macros va_start, va_copy, va_arg, and va_end
- What is va_start?
gets the address of the first argument.
- What is va_arg?
dereference the block address and type cast it to the appropriate type. then goes to the next block of memory. What is a "Type Descriptor"?
- What is va_end?
performs cleanup for an ap object initialized by a call to va_start or va_copy
The printf function supports a wide range of format specifiers that allow for the formatting of output in a variety of ways. Here are the format specifiers that are supported in this implementation of printf:
%d: for integers
%s: for strings
%f: for floats/doubles
%b: for binary
%u: for unsigned integers
%o: for octal numbers
%x: for hexadecimal numbers (lowercase)
%X: for hexadecimal numbers (uppercase)
%S: for non-printable characters
%p: for pointer addresses
%r: for reversed strings
%R: for rot13'ed strings
To create our custom printf function, We need to plan out how it will work. We can create a flowchart to help us visualize the logic of the function. Here is an example of a simple flowchart for printf:
- start -> read format string -> while format string not empty ->
- parse next format specifier -> output text before specifier ->
- if specifier is %d -> output decimal number
- if specifier is %s -> output string
- if specifier is %c -> output character
- if specifier is %% -> output %
- if specifier is unknown -> output error
- end loop -> output remaining text -> end