Performs processing relating to input/output of stream input/output file.
The following constants (macros) are all implementation-defined.
Indicates a structure type that stores various control information including a pointer to the buffer, an error indicator, and an end-of-file indicator, which are required for stream input/output processing. |
||
Indicates full buffering of input/output as the buffer area usage method. |
||
Indicates line buffering of input/output as the buffer area usage method. |
||
Indicates non-buffering of input/output as the buffer area usage method. |
||
Indicates the buffer size required for input/output processing. |
||
Indicates the size of an array large enough to store a string of a temporary file name generated by the tmpnam function. |
||
Indicates a shift of the current file read/write position to an offset from the current position. |
||
Indicates a shift of the current file read/write position to an offset from the end-of-file position. |
||
Indicates a shift of the current file read/write position to an offset from the beginning of the file. |
||
Indicates the number of files for which simultaneous opening is guaranteed by the implementation. |
||
Indicates the maximum number of unique file names that shall be generated by the tmpnam function. |
||
Outputs stream input/output file buffer contents to the file. |
||
Opens a stream input/output file under the specified file name. |
||
Closes a currently open stream input/output file and reopens a new file under the specified file name. |
||
Defines and sets a stream input/output buffer area on the user program side. |
||
Defines and sets a stream input/output buffer area on the user program side. |
||
Outputs data to a stream input/output file according to a format. |
||
Outputs a variable parameter list to the specified stream input/output file according to a format. |
||
Converts data according to a format and outputs it to the standard output file (stdout). |
||
Outputs a variable parameter list to the standard output file (stdout) according to a format. |
||
Converts data according to a format and outputs it to the specified area. |
||
Inputs data from the specified storage area and converts it according to a format. |
||
snprintf <-lang=c99> |
Converts data according to a format and writes it to the specified array. |
|
vsnprintf <-lang=c99> |
Equivalent to snprintf with the variable argument list replaced by va_list. |
|
vfscanf <-lang=c99> |
Equivalent to fscanf with the variable argument list replaced by va_list. |
|
vscanf <-lang=c99> |
Equivalent to scanf with the variable argument list replaced by va_list. |
|
vsscanf <-lang=c99> |
Equivalent to sscanf with the variable argument list replaced by va_list. |
|
Inputs data from a stream input/output file and converts it according to a format. |
||
Inputs data from the standard input file (stdin) and converts it according to a format. |
||
Outputs a variable parameter list to the specified area according to a format. |
||
(macro) Inputs one character from a stream input/output file. |
||
(macro) Outputs one character to a stream input/output file. |
||
Inputs data from a stream input/output file to the specified storage area. |
||
Outputs data from a storage area to a stream input/output file. |
||
Shifts the current read/write position in a stream input/output file. |
||
Obtains the current read/write position in a stream input/output file. |
||
Shifts the current read/write position in a stream input/output file to the beginning of the file. |
||
Outputs an error message corresponding to the error number to the standard error file (stderr). |
||
Indicates the maximum number of files that can be opened simultaneously. |
||
Indicates the maximum length of a file name that can be held. |
Implementation-Defined Specifications
(a) The output format of perror function is
<string>:<error message for the error number specified in error>
(b) Table 7.8 shows the format when displaying the floating-point infinity and not-a-number in printf and fprintf functions.
An example of a program that performs a series of input/output processing operations for a stream input/output file is shown in the following.
1 #include <stdio.h>
2
3 void main( )
4 {
5 int c;
6 FILE *ifp, *ofp;
7
8 if ((ifp=fopen("INPUT.DAT","r"))==NULL){
9 fprintf(stderr,"cannot open input file\n");
10 exit(1);
11 }
12 if ((ofp=fopen("OUTPUT.DAT","w"))==NULL){
13 fprintf(stderr,"cannot open output file\n");
14 exit(1);
15 }
16 while ((c=getc(ifp))!=EOF)
17 putc(c, ofp);
18 fclose(ifp);
19 fclose(ofp);
20 }
This program copies the contents of file INPUT.DAT to file OUTPUT.DAT.
Input file INPUT.DAT is opened by the fopen function in line 8, and output file OUTPUT.DAT is opened by the fopen function in line 12. If opening fails, NULL is returned as the return value of the fopen function, an error message is output, and the program is terminated.
If the fopen function ends normally, the pointer to the data (FILE type) that stores information on the opened files is returned; these are set in variables ifp and ofp.
After successful opening, input/output is performed using these FILE type data.
When file processing ends, the files are closed with the fclose function.