[ First ]  [ Previous ]  [ Next ]  [ Last ]  [ Manuals ]


fgetc

Read the next character from a stream.

Compatibility:

This function is compatible with the following targets:

ANSI

BeOS

EMB/RTOS

Mac OS

Palm OS

Win32


Prototype:
#include <stdio.h>
int fgetc(FILE *stream);
Parameters:

Parameters for this facility are:

stream  
FILE *  
A pointer to a FILE stream  

Remarks:

The fgetc() function reads the next character from stream and advances its file position indicator.


NOTE

On embedded/ RTOS systems this function only is implemented for stdin, stdout and stderr files.
Return:

fgetc() returns the character as an int. If the end-of-file has been reached, fgetc() returns EOF.

If the file is opened in update mode (+) a file cannot be read from and then written to without repositioning the file using one of the file positioning functions (fseek(), fsetpos(), or rewind()) unless the last read or write reached the end-of-file.

See Also:

"Wide Character and Byte Character Stream Orientation"

"getc"

"getchar"

Example of fgetc() usage.:
#include <stdio.h>
#include <stdlib.h>

int main(void)
{
	FILE *f;
	char filename[80], c;

	// get a filename from the user	
	printf("Enter a filename to read.\n");
	gets(filename);

	// open the file for input
	if (( f = fopen(filename, "r")) == NULL) {
		printf("Can't open %s.\n", filename);
		exit(1);
	}

	// read the file one character at a time until
	// end-of-file is reached
	while ( (c = fgetc(f)) != EOF)
		putchar(c);			// print the character

	// close the file
	fclose(f);

	return 0;
}


[ First ]  [ Previous ]  [ Next ]  [ Last ]  [ Manuals ]

Visit the Metrowerks website at: http://www.metrowerks.com
For assistance contact Metrowerks Technical Support at: cw_support@metrowerks.com
Copyright © 2000, Metrowerks Corp. All rights reserved.

Last updated: August 16, 2000