开发者

Just how many printf and scanf variants are there? [closed]

开发者 https://www.devze.com 2023-01-17 07:43 出处:网络
开发者_如何学JAVA It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical andcannot be reasonably answered in its current for
开发者_如何学JAVA It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 12 years ago.

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?


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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消