What Is a Stream? :: Ascribe & Achievement
A beck is a arrangement of characters. Added exactly, it is a arrangement of bytes
of data. A arrangement of bytes abounding into a program is an ascribe stream; a arrangement
of bytes abounding out of a program is an achievement stream. By absorption on streams,
we don t accept to anguish as abundant about area they re traveling or area they originated.
The above advantage of streams, therefore, is that input/output program ming
is accessory independent. Programmers don t charge to address appropriate input/output
functions for anniversary accessory (keyboard, disk, and so on). The program sees input/output
as a connected beck of bytes no amount area the ascribe is advancing from or
traveling to.
Every C beck is affiliated to a file. In this context, the appellation book doesn t
accredit to a deejay file. Rather, it is an average move amid the beck
that the program deals with and the absolute concrete accessory getting acclimated for ascribe
or output. For the alotof part, the alpha C program mer doesn t charge to be
anxious with these files, because the data of interactions amid streams,
files, and accessories are taken affliction of automatically by the C library functions
and the operating system.
Modes of Streams in C Language
C streams can be disconnected into two modes: argument and binary.
Text Stream
A argument beck consists alone of characters, such as argument data getting beatific to
the screen. Argument streams are organized into lines, which can be up to 255 characters
continued and are concluded by an end-of-line, or newline, character. Assertive characters
in a argument beck are accustomed as accepting appropriate meaning, such as the newline
character.
Binary Stream
A bifold beck can handle any array of data, including, but not bound to,
argument data. Bytes of data in a bifold beck aren t translated or interpreted
in any appropriate way; they are apprehend and accounting absolutely as-is. Bifold streams
are acclimated primarily with deejay files.
Predefined Streams
ANSI C has three predefined
streams, aswell referred to as the accepted input/output files. If you re
program ming for an IBM-compatible PC active DOS, two added accepted
streams are accessible to you. These streams are automatically opened if a C
program starts active and are bankrupt if the program terminates. The
programmer doesn t charge to yield any appropriate activity to create these streams
available. Table lists the accepted streams and the accessories they commonly are
connected with. All 5 of the accepted streams are text-mode
streams.
| The 5 standard streams. | ||
|---|---|---|
| NAME | STREAM | DEVICE |
| stdin | Standard Input | Keyboard |
| stdout | Standard Output | Screen |
| stderr | Standard Error | Screen |
| stdprn* | Standard Printer | Printer (LPT1) |
| stdaux* | Standard Auxiliary | Serial Anchorage (COM1) |
| (*) Accurate alone beneath DOS | ||
Whenever we accept to use the printf() or puts() functions to affectation argument on-screen,
we use the stdout stream. Likewise, if we use gets() or scanf() to apprehend keyboard
input, we use the stdin stream. The accepted streams are opened automatically,
but additional streams, such as those acclimated to dispense advice stored on disk,
haveto be opened explicitly.
|
Tags: program, files, characters, functions, automatically, streams, device, special streams, stream, input, output, standard, program, binary, bytes, files, sequence, characters, special, device, functions, automatically, , streams are, standard streams, input output, text stream, binary stream, |
Also see ...
PermalinkArticle In : Computers & Technology - C Language Programming