C Programming Language
  • Home
  • C Fundamentals
    • C Character Set
    • Tokens>
      • Keywords
      • Identifiers
      • Constants>
        • Definition and Its types
        • Numeric Constants>
          • Integer Constants
          • Real Constants
        • Character Constants
        • String Constants
        • Backslash Character
      • Operators>
        • Definition and Its types
        • Arithmetic
        • Relational
        • Logical
        • Increment
        • Decrement
        • Assignment
        • Arithmetic Assignment
        • Conditional
        • Bitwise
        • Special Operators
        • Hierarchy
    • Data Types>
      • Primary (Or) Basic
      • User-Defined
      • Derived
    • Variable>
      • Definition
      • Declaration
      • Initialization
  • Control Structures
    • Decision-Control>
      • If Statement>
        • Simple-if Statement
        • if-else Statement
        • Nested-if Statement
        • if-else ladder Statement
      • Switch Statement
    • Loop Control>
      • For
      • While
      • Do-While
  • Arrays
    • Introduction
    • Single-Dimensional>
      • Definition
      • Declaration
      • Initialization
    • Two-Dimensional>
      • Definition
      • Declaration
      • Initialization
    • Multi-Dimensional>
      • Definition
      • Declaration
      • Initialization
  • Functions
    • Definition
    • Standard Library Character Functions
    • Standard Library String Functions
    • Storage Classes>
      • Definition
      • Automatic
      • Register
      • Static
      • External
  • Pointers
  • Files
    • Concepts
    • Data Files and its Categories
    • Standard Files and its Categories
  • University Questions
    • April 2001 To 2005
    • April 2006 To 2010
    • April 2011 To 2015
    • November 2001 To 2005
    • November 2006 To 2010
    • November 2011 To 2015

Standard Files

When a C program begins its execution, it has to access three files.

Ø  Standard input file
Ø  Standard output file
Ø  Standard error file

Standard input file:    The first file is the standard input file from which the input is received, usually it is a keyboard. Input can also be redirected from a disk file. As long                                         as the program reads the input from the beginning to its end, it need not be concerned about where the characters are coming from.

standard output file:  The second file is the standard output file to which the output is sent; usually it is the visual display unit (i.e. screen). Output can also be redirected                                         to store into the disk file. As long as the program reads the input from the beginning to its end, it need not be concerned about where the characters                                         are coming from.

standard error file:    The third file is the standard error file. The purpose of this file is to keep error messages separate from other program output (i.e. if the standard                                             output is displayed in the screen) so that the error messages are stored in the disk file and vice-versa.
  • The stdin, stdout, and stderr are file type pointers defined in the header file stdio.h.
  • The standard input device (keyboard), standard output and error device (VDU) are called as the stdin, stdout, and stderr respectively. These file type pointers are treated as files in C.
  • File related operations can be performed on these files just as other ordinary files.

For example

    @    The statement x=fgetc(stdin); accepts a single character as input from the standard input device (i.e. keyboard) and assigns it to the variable x.

    @    The statement fputc(x, stdout); displays the character as output on the standard output device (i.e screen) which is assigned to the variable x.

    @    The statement fputc(x, stderr); also displays the character as output on the screen which is assigned to x. Even though the VDU is the output and error device,                     there are differences these two files.
Powered by Create your own unique website with customizable templates.