tags:

views:

88

answers:

2

There are so many different versions of printf and scanf in C that it brings out a chuckle in me. Let's start:

  • printf: original implementation; uses format then the values as arguments
  • fprintf: the same, but takes a FILE pointer before format
  • sprintf: takes a char pointer before format
  • snprintf: same as above, but limits size written for buffer overflow safety
  • vprintf: like printf but takes a va_list of value arguments
  • vfprintf: the va_list equivalent of fprintf
  • vsprintf: the va_list equivalent of sprintf
  • vsnprintf: the va_list equivalent of snprintf
  • asprintf: takes a char ** before format and allocates memory on the pointer
  • vasprintf: the same as above, but uses va_list
  • scanf: reads format into arguments after it from stdin
  • fscanf: takes a FILE pointer before format, reading from it instead
  • sscanf: takes a char pointer before format, reading from it instead
  • vscanf: the va_list function analogical to scanf
  • vfscanf: the va_list function analogical to fscanf
  • vsscanf: the va_list function analogical to sscanf

Thanks to dreamlax, the ones that work with wchar_t:

  • wprintf: original implementation using wchar_t everywhere that char * was
  • fwprintf: writes to a FILE pointer before format, using wchar_t
  • swprintf: writes to a char pointer before format, using wchar_t
  • vwprintf: writes to stdin, taking a va_list instead of normal arguments
  • vfwprintf: writes to a FILE pointer, taking a va_list instead of normal arguments
  • vswprintf: writes to a char pointer, taking a va_list instead of normal arguments

Are there any more?

A: 

You're missing all of the ones that operate on wchar_t.

dreamlax
Yay, let's double the amount of functions! *adds them to the list*
Delan Azabani
+2  A: 

While there are a lot, usually all but vfprintf and vfwprintf are simply wrappers for these two which pass an appropriate FILE * (possibly a special one setup for writing to a string instead of to a file on disk) and optionally call va_start and va_end (depending on if they're the "v" version or the plain version.

R..