A stream is associated with an external file (which may be a physical device)
by opening a file. This is also the case when a new file is created. Creating an existing file causes its former contents to be discarded if necessary. If a file can support positioning requests (such as a disk file, as opposed to a terminal), then a file position indicator associated with the stream is positioned at the start (byte number 0) of the file, unless the file is opened with append mode, in which case the file position indicator may be initially positioned at the beginning or end of the file. The file position indicator facilitates subsequent reads, writes and positioning requests on the file. All input takes place as if bytes were read by successive calls to fgetc
; all output takes place as if bytes were written by successive calls to fputc()
.