twitter
    Find out what I'm doing, Follow Me :)

The Stdio.H Header File

Load the file simpleio.c for our first look at a file with standard I/O. Standard I/O refers to the most usual places where data is either read from, the keyboard, or written to, the video monitor. Since they are used so much, they are used as the default I/O devices and do not need to be named in the Input/Output instructions. This will make more sense when we actually start to use them so lets look at the file in front of you.

# include "/sys/stdio.h" /* standard header for input/output */

main( )
{
char c;
printf("Enter any characters, X = halt program.\n");
do {
c = getchar(); /* Get a character from the kb */
putchar(c); /* Display the character on the monitor */
} while (c != ’X’); /* Until and X is hit */
printf("\nEnd of program.\n");
}



The first thing you notice is the first line of the file, the #include "stdio.h" line. This is very much like the #define we have already studied, except that instead of a simple substitution, an entire file is read in at this point. The system will find the file named "stdio.h" and read its entire contents in, replacing this statement. Obviously then, the file named "stdio.h" must contain valid C source statements that can be compiled as part of a program. This particular file is composed of several standard #defines to define some of the standard I/O operations. The file is called a header file and you will find several different header files on the source disks that came with your compiler. Each of the header files has a specific purpose and any or all of them
can be included in any program.

Most C compilers use the double quote marks to indicate that the "include" file will be found in the current directory. A few use the "less than" and "greater than" signs to indicate that the file will be found in a standard header file. Nearly all MSDOS C compilers use the double quotes, and most require the "include" file to be in the default directory. All of the programs in this tutorial have the double quotes in the "include" statements. If your compiler uses the other notation, you will have to change them before compiling.