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

Read the next character from a stream.
Compatibility:
This function is compatible with the following targets:
Prototype:
#include <stdio.h>
int getc(FILE *stream);
Parameters:
Parameters for this facility are:
Remarks:
The getc() function reads the next character from stream, advances the file position indicator, and returns the character as an int value. Unlike the fgetc() function, getc() is implemented as a macro.
If the file is opened in update mode (+) it cannot be read from and then written to without being repositioned using one of the file positioning functions (fseek(), fsetpos(), or rewind()) unless the last read or write reached the end-of-file.
Return:
getc() returns the next character from the stream or returns EOF if the end-of-file has been reached or a read error has occurred.
See Also:
"Wide Character and Byte Character Stream Orientation"
"fgetc"
"fputc"
"getchar"
"putchar"
Example of getc() 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");
scanf("%s", filename);
// open a file for input
if (( f = fopen(filename, "r")) == NULL) {
printf("Can't open %s.\n", filename);
exit(1);
}
// read one character at a time until end-of-file
while ( (c = getc(f)) != EOF)
putchar(c);
// 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