Just how many printf and scanf variants are there? [closed]
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; usesformatthen the values as argumentsfprintf: the same, but takes aFILEpointer beforeformatsprintf: takes acharpointer beforeformatsnprintf: same as above, but limits size written for buffer overflow safetyvprintf: likeprintfbut takes ava_listof value argumentsvfprintf: theva_listequivalent offprintfvsprintf: theva_listequivalent ofsprintfvsnprintf: theva_listequivalent ofsnprintfasprintf: takes achar **beforeformatand allocates memory on the pointervasprintf: the same as above, but usesva_listscanf: readsformatinto arguments after it fromstdinfscanf: takes aFILEpointer beforeformat, reading from it insteadsscanf: takes acharpointer beforeformat, reading from it insteadvscanf: theva_listfunction analogical toscanfvfscanf: theva_listfunction analogical tofscanfvsscanf: theva_listfunction analogical tosscanf
Thanks to dreamlax, the ones that work with wchar_t:
wprintf: original implementation usingwchar_teverywhere thatchar *wasfwprintf: writes to aFILEpointer beforeformat, usingwchar_tswprintf: writes to acharpointer beforeformat, usingwchar_tvwprintf: writes tostdin, taking ava_listinstead of normal argumentsvfwprintf: writes to aFILEpointer, taking ava_listinstead of normal argumentsvswprintf: writes to acharpointer, taking ava_listinstead 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.
加载中,请稍侯......
精彩评论