fprintf introduction of C + + language functions: fprintf function transfer format output to a file usage #include <stdio.h> int fprintf (file *stream, const char *format, ...); The fprintf () function sends information (parameters) to the file specified by the stream (stream) according to the specified format (format) (format). fprintf () can only work as printf (). The return value of fprintf () is the number of characters in the output and a negative value when an error occurs. Returns the number of bytes converted when a value is successful, and returns a negative when it fails. Successful return of 0 in the Linux/unix system, failure return-1. And the errno value is placed. Program/* Programs to create backup of the AUTOEXEC. BAT file */#include <stdio.h> int main (void) {file *in, *out; if (in = fopen ("//autoexec. BAT "," rt ") = = NULL) {fprintf (stderr," Cannot open input file./n "); return 1; The IF (out = fopen ("//autoexec"). BAK "," wt ") = = NULL) {fprintf (stderr," Cannot open output file./n "); return 1; while (!feof (in)) FPUTC (Fgetc (in), out); Fclose (in); Fclose (out); return 0; Example usage: #include <stdio.h> #include <process.h> FILE *stream; void Main (void) {int i = 10; Double fp = 1.5; Char s[] = "This is a string"; char c = '/n '; stream = fopen ("FprintF.out "," w "); fprintf (Stream, "%s%c", S, c); fprintf (Stream, "%d/n", I); fprintf (Stream, "%f/n", FP); Fclose (stream); System ("type Fprintf.out"); Screen output: This is a string 10 1.500000 format specifier%d decimal signed integer%u decimal unsigned integer%f floating-point number%s string%c single character%p pointer value %e exponential form of floating point%x,%x unsigned integer%0 with hexadecimal notation An octal representation of an integer%g automatically chooses an appropriate representation