fprintf_s, fwprintf_s
Go Up to stdio.h Index
Header File
stdio.h
Category
Formatted input/output functions
Prototype
int fprintf_s(FILE * restrict stream, const char * restrict format, [,argument, ...]);
int fwprintf_s(FILE * restrict stream, const wchar_t * restrict format, [,argument, ...]);
Description
Replaces fprintf, fwprintf adding security enhancements.
fprintf_s accepts a series of arguments applied to each format specifier contained in the format string pointed to by format. It outputs the formatted data to stream. The number of format specifiers must be the same as the number of arguments and conversely.
Note: For details on format specifiers, see Printf Format Specifiers.
In addition to fprintf, fprintf_s has additional run-time constraints referring to the fact that the %n specifier may not be contained in format and the corresponding argument to a %s specifier in the arguments list must not be a null pointer.
In case of an error, fprintf_s stops producing output.
Return Value
fprintf_s returns the number of characters transmitted. In case of error, it returns a negative value.
Example
#include <stdio.h> int main(void) { FILE *stream; int i = 100; char c = 'C'; float f = 1.234; /* Open a file for update */ if(fopen_s(&stream,"DUMMY.FIL", "w+")){ printf("Unable to create DUMMY.FIL"); } else{ /* Write some data to the file */ fprintf_s(stream, "%d %c %f", i, c, f); } /* Close the file */ fclose(stream); return 0; }
Portability
POSIX | Win32 | ANSI C | ANSI C++ | |
---|---|---|---|---|
fprintf_s |
+ |
+ |
+ |
+ |
fwprintf_s |
+ |
+ |
+ |