Is there a general-purpose printf-ish routine defined in any C standard

Posted by supercat on Stack Overflow See other posts from Stack Overflow or by supercat
Published on 2011-03-15T15:51:34Z Indexed on 2011/03/16 0:10 UTC
Read the original article Hit count: 224

Filed under:
|
|

In many C libraries, there is a printf-style routine which is something like the following:

int __vgprintf(void *info, (void)(*print_function(void*, char)), const char *format, va_list params);

which will format the supplied string and call print_function with the passed-in info value and each character in sequence. A function like fprintf will pass __vgprintf the passed-in file parameter and a pointer to a function which will cast its void* to a FILE* and output the passed-in character to that file. A function like snprintf will create a struct holding a char* and length, and pass the address of that struct to a function which will output each character in sequence, space permitting.

Is there any standard for such a function, which could be used if e.g. one wanted a function to output an arbitrary format to a TCP port? A common approach is to allocate a buffer one hopes is big enough, use snprintf to put the data there, and then output the data from the buffer. It would seem cleaner, though, if there were a standard way to to specify that the print formatter should call a user-supplied routine with each character.

© Stack Overflow or respective owner

Related posts about c

    Related posts about printf