I am trying to create a function like:
void my_printf(char *fmt, ...) which behaves like printf, except that it will also record all the argument passed in to a text file. Can anybody tell me how to do this?
Thanks.
Printable View
I am trying to create a function like:
void my_printf(char *fmt, ...) which behaves like printf, except that it will also record all the argument passed in to a text file. Can anybody tell me how to do this?
Thanks.
My initial thought:
Call my_printf just like you would call printf. Inside of my_printf, use va_list, va_start, va_arg, and va_end to extract the var args. Do what you will with them. Then, call vprintf with the va_list.
You will know how many arguments were passed by the number of %'s (take %% into account, of course) in char* fmt...