fgetc, fgetwc (Windows CE 5.0)

Send Feedback

Developing an Application > Microsoft C Run-time Library for Windows CE > Run-time Library Reference

Read a character from a stream.

int fgetc(    FILE*stream);wint_t fgetwc(    FILE*stream);

Parameters

  • stream
    Pointer to FILE structure.

Return Values

fgetc returns the character read as an int or return EOF to indicate an error or end of file.

fgetwc returns, as a wint_t, the wide character that corresponds to the character read or return WEOF to indicate an error or end of file.

For both functions, use feof or ferror to distinguish between an error and an end-of-file condition.

For both functions, if a read error occurs, the error indicator for the stream is set.

Remarks

Each of these functions reads a single character from the current position of a file. This is the file associated with stream. The function then increments the associated file pointer (if defined) to point to the next character. If the stream is at end of file, the end-of-file indicator for the stream is set.

Routine-specific remarks follow.

Routine Remarks
fgetc Implemented only as a function, rather than as a function and a macro.
fgetwc Wide-character version of fgetc.

Reads c as a multibyte character or a wide character according to whether stream is opened in text mode or binary mode.

Generic-Text Routine Mappings

TCHAR.H Routine
_fgettc
_fgettchar

For more information about TCHAR.H routines, see Generic Text Mappings.

Example

/* FGETC.C: 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.
 */

#include <stdio.h>
#include <stdlib.h>

void main( void )
{
   FILE *stream;
   char buffer[81];
   int  i, ch;

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

   /* Read in first 80 characters and place them in "buffer": */
   ch = fgetc( stream );
   for( i=0; (i < 80 ) && ( feof( stream ) == 0 ); i++ )
   {
      buffer[i] = (char)ch;
      ch = fgetc( stream );
   }

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

Output

/* FGETC.C: This program uses getc to read the first
 * 80 input characters (or

Requirements

OS Versions: Windows CE 2.0 and later.
Header: stdlib.h.
Link Library: coredll.dll.

See Also

fputc

Send Feedback on this topic to the authors

Feedback FAQs

© 2006 Microsoft Corporation. All rights reserved.