Challenge
Write a function that implements C printf
-style string formatting.
Rules
- You must implement at least
%%
,%c
,%s
,%d
and%f
. - You must not use a built-in string formatting method.
- You must not run external programs or connect to the Internet from your program.
- It's up to you to decide how to handle invalid input, but your program must not terminate abnormally.
- You should write a variadic function if possible.
The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be interpreted as described in RFC 2119.
%c
do? Pretty sure%s
,%d
and%f
are for strings, ints and floats respectivelly, but unsure about%c
. \$\endgroup\$%c
displays the ASCII value of a passed-in int IIRC \$\endgroup\$97
and'a'
would both becomea
on the output. \$\endgroup\$%-02d
right? just that three %c, %s, %d? \$\endgroup\$