Deadline: September 22nd, 2014

1   Instructions

You must implement the following function:

int st_printf(st_t *, const char *fmt, ...);


2   Function semantics

st_printf is based on the previous assignment (MyStream). It must format its arguments and output them to the stream identified by its first argument, buffering the output as needed.

The format string is composed of zero or more directives: ordinary characters (not “%”), which are copied unchanged to the output stream; and conversion specifications, each of which results in fetching zero or more subsequent argument. st_printf must recognize the following conversions:

Conversion Meaning
%c An int argument is converted to unsigned char, and the resulting character is written.
%s A const char* argument is written as a nul-terminated string.
%p The value of a pointer is written in hexadecimal with a 0x prefix, or the string “null” if the pointer is equal to 0.
%d / %ld A int/long argument is written in decimal.
%u / %lu A unsigned/unsigned long argument is written in decimal.
%x / %lx An unsigned/unsigned long argument is written in hexadecimal.
%% A single “%” is written; no argument is converted.

The function must return the number of characters written/buffered, or 0 if no character could be written.

You may implement the following for a higher grade:

3   Grading