Definition | #include <stdio.h> int fprintf(FILE *fp, const char *format, argumentlist);
|
Parameters | FILE *fp File pointer to the output file. const char *format Format string as described under printf with KR or ANSI functionality (see argumentlist Variables or constants whose values are to be converted and formatted for output |
Return val. | number of characters output if successful. Negative value if an error occurs. |
Notes |
The characters are not written immediately to the external file but are stored in an internal Maximum number of characters to be output With KR functionality (applies to C/C++ versions prior to V3.0 only) a maximum of 1400 Attempts to output non-initialized variables or to output variables in a manner inconsistent The behavior is undefined if the percent sign (%) in a format statement is followed by an The following applies in the case of text files with SAM access mode and variable record |
Example | #include <stdio.h> #include <stdlib.h> int main(void) { FILE *fp; char c, name[40]; int i; char *string; double d; printf("Name of the output file: \n"); gets(name); if((fp = fopen(name,"w")) == NULL) { printf("Can't open %s\n", name); exit(1); } c = 'A'; i = 999; string = "This is a string."; d = 123.456; fprintf(fp, "%c %d %s %f\n", c, i, string, d); fclose(fp); puts("Correct output to file:A 999 This is a string. 123.456000"); return 0; } |
See also | printf, sprintf, snprintf, putc, putchar, puts, scanf, fscanf |