Content deleted Content added
→Member types: demonstrate a trivial edit that could have been made to the wording so that the literal word sequence "FILE pointer" (rather than "pointer to a FILE") can be located with Ctrl/Cmd+F. This edit is intended to be reverted. Tag: Reverted |
No edit summary Tags: Mobile edit Mobile app edit iOS app edit App section source |
||
(19 intermediate revisions by 15 users not shown) | |||
Line 2:
{{Use dmy dates|date=February 2022}}
{{C Standard Library}}
The [[C (programming language)|C programming language]] provides many [[standard library]] [[subroutine|functions]] for [[computer file|file]] [[input/output|input and output]]. These functions make up the bulk of the [[C standard library]] [[header file|header]] {{mono|<'''stdio.h'''>}}.<ref>{{cite book |title=ISO/IEC 9899:1999 specification |at=p. 274, § 7.19 |language=en-US}}</ref> The functionality descends from a "portable I/O package" written by [[Mike Lesk]] at [[Bell Labs]] in the early 1970s,<ref>{{cite book |last1=Kernighan |first1=Brian |author-link1=Brian Kernighan |last2=Pike |first2=Rob |author-link2=Rob Pike |title=[[The UNIX Programming Environment]] |publisher=[[Prentice Hall]] |___location=[[Englewood Cliffs]] |year=1984 |page=200|bibcode=1984upe..book.....K }}</ref> and officially became part of the [[Unix]] operating system in [[Version 7 Unix|Version 7]].<ref name="reader">{{cite
The I/O functionality of C is fairly low-level by modern standards; C abstracts all file operations into operations on [[stream (computing)|stream]]s of [[byte]]s, which may be "input streams" or "output streams". Unlike some earlier programming languages, C has no direct support for [[random access|random-access]] data files; to read from a record in the middle of a file, the programmer must create a stream, [[fseek|seek]] to the middle of the file, and then read bytes in sequence from the stream.
Line 9:
==Overview==
This library uses what are called streams to operate with physical devices such as keyboards, printers, terminals or with any other type of files supported by the system. Streams are an abstraction to interact with these in a uniform way. All streams have similar properties independent of the individual characteristics of the physical media they are associated with.<ref>{{Cite web |title=(stdio.h) - C++ Reference |url=http://www.cplusplus.com/reference/cstdio/
===Functions===
Line 21:
! Description
|-
! rowspan=
| colspan=2 style="text-align:center;font-family:monospace" | {{anchor|fopen}}[https://en.cppreference.com/w/c/io/fopen fopen]
| Opens a file (with a non-Unicode filename on Windows and possible UTF-8 filename on Linux)
|-
| colspan=2 style="text-align:center;font-family:monospace" | {{anchor|popen}}[https://man7.org/linux/man-pages/man3/popen.3.html popen]
| opens a process by creating a pipe, forking, and invoking the shell
|-
| colspan=2 style="text-align:center;font-family:monospace" | {{anchor|freopen}}[https://en.cppreference.com/w/c/io/freopen freopen]
Line 33 ⟶ 36:
| colspan=2 style="text-align:center;font-family:monospace" | {{anchor|fclose}}[https://en.cppreference.com/w/c/io/fclose fclose]
| Closes a file
|-
| colspan=2 style="text-align:center;font-family:monospace" | {{anchor|pclose}}[https://man7.org/linux/man-pages/man3/pclose.3p.html pclose]
| closes a stream
|-
| colspan=2 style="text-align:center;font-family:monospace" | {{anchor|setbuf}}[https://en.cppreference.com/w/c/io/setbuf setbuf]
Line 93 ⟶ 99:
|-
| style="font-family:monospace" | {{anchor|vscanf|vfscanf|vsscanf}}[https://en.cppreference.com/w/c/io/vscanf vscanf]<br />[https://en.cppreference.com/w/c/io/vfscanf vfscanf]<br />[https://en.cppreference.com/w/c/io/vsscanf vsscanf]
| style="font-family:monospace" | {{anchor|vwscanf|vfwscanf|
| Reads formatted input byte/{{mono|wchar_t}} from stdin,<br />a file stream or a buffer using variable argument list
|-
Line 204 ⟶ 210:
|-
! style="font-family:monospace" | [[Standard streams#Standard input (stdin)|stdin]]
| A pointer to a {{mono|FILE}}
|-
! style="font-family:monospace" | [[Standard streams#Standard output (stdout)|stdout]]
| A pointer to a {{mono|FILE}}
|-
! style="font-family:monospace" | [[Standard streams#Standard error (stderr)|stderr]]
| A pointer to a {{mono|FILE}}
|}
===Member types===
Data types defined in the {{mono|<stdio.h>}} header include:
*{{mono|[https://en.cppreference.com/w/c/io FILE]}} –
**platform-specific identifier of the associated I/O device, such as a [[file descriptor]]
**the buffer
Line 241 ⟶ 247:
int main(void) {
char buffer[5];
size_t len;
FILE* fp = fopen("myfile", "rb");
Line 248 ⟶ 255:
}
▲ fputs("An error occurred while reading the file.\n", stderr);
▲ return EXIT_FAILURE;
}▼
buffer[i] = rc;▼
}
fclose(fp);
printf("The bytes read were
for (int i = 0; i < len; ++i) {
putchar('\n');
return EXIT_SUCCESS;
Line 268 ⟶ 274:
==Alternatives to stdio{{anchor|Sfio}}==
{{Redirect|Sfio|other uses of "SFIO"|SFIO (disambiguation)}}
Several alternatives to {{mono|stdio}} have been developed. Among these
▲Several alternatives to {{mono|stdio}} have been developed. Among these is the [[Input/output (C++)|C++ {{mono|iostream}}]] library, part of the [[ISO C++|ISO C++ standard]]. ISO C++ still requires the {{mono|stdio}} functionality.
Other alternatives include the
==See also==
|