Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ fgetc(DOS) — System V/386 Software Development System 3.2.2b

Media Vault

Software Library

Restoration Projects

Artifacts Sought

     Name
          fgetc, fgetchar - Get a character from a stream.

     Syntax
          #include <stdio.h>

          int fgetc(stream)
          FILE *stream;

          int fgetchar(void)

     Description
          The fgetc function reads a single character as an unsigned
          char converted to an int from the input stream at the
          current position. The function then increases the associated
          file pointer (if any) to point to the next character. The
          fgetchar function is equivalent to fgetc(stdin).

     Return Value
          The fgetc and fgetchar functions return the character read.
          A return value of EOF may indicate an error or end-of-file;
          however, the EOF value is also a legitimate integer value,
          so feof or ferror should be used to distinguish between an
          error and an end-of-file condition.

     See Also
          fputc(DOS), fputchar(DOS), getc(S), getchar(S)

     Notes
          The fgetc and fgetchar routines are identical to getc and
          getchar, but are functions, not macros.

     Example
          #include <stdio.h>

          FILE *stream; char buffer[81]; int i; int ch;

          main()
           {

                  /* Open file to read line from: */
                  stream = fopen("fgetc.c", "r");

                  /* Read in first 80 characters and */
                  /*  place them in "buffer": */

                  ch = fgetc(stream);
                  for(i=0;(i < 80)&&(feof(stream) == 0)&&
                          (ch != '\n'));i++) {
                                  buffer[i]=ch;
                                  ch = fgetc(stream);
                          }

                  /* Add null to end string */
                  buffer[i] = '\0';
                  printf( "%s\n", buffer );
           }

          This program uses getc to read the first 80 input characters
          (or until the end of input) and place them into a string
          named buffer.

                                                (printed 6/18/89)



Typewritten Software • bear@typewritten.org • Edmonds, WA 98026