C file input/output: Difference between revisions

Content deleted Content added
WL
en-US
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 |url=http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1124.pdf |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}}</ref> and officially became part of the [[Unix]] operating system in [[Version 7 Unix|Version 7]].<ref name="reader">{{cite techreport |first1=M. D. |last1=McIlroy |author-link1=Doug McIlroy |year=1987 |url=http://www.cs.dartmouth.edu/~doug/reader.pdf |title=A Research Unix reader: annotated excerpts from the Programmer's Manual, 1971–1986 |series=CSTR |number=139 |institution=Bell Labs}}</ref>
 
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.