.TH fgetc() "" "" "STDIO Function (libc)"
.PC "Read character from stream"
.B "#include <stdio.h>"
\fBint fgetc(\fIfp\^\fB) FILE *\fIfp\^\fB;\fR
.PP
.B fgetc()
reads characters from the input stream
.IR fp .
In general, it behaves the same as the macro
.BR getc() :
it runs more slowly than
.BR getc() ,
but yields a smaller object module when compiled.
.SH Example
This example counts the number of lines and \*(QLsentences\*(QR
in a file.
.DM
#include <stdio.h>
.DE
.DM
main()
{
	FILE *fp;
	int filename[20];
	int ch;
	int nlines = 0;
	int nsents = 0;
.DE
.DM
	printf("Enter file to test: ");
	gets(filename);
.DE
.DM
	if ((fp = fopen(filename,"r")) == NULL) {
		printf("Cannot open file %s.\en", filename);
		exit(1);
	}
.DE
.DM
	while ((ch = fgetc(fp)) != EOF) {
		if (ch == '\en')
			++nlines;
.DE
.DM
		else if (ch == '.' || ch == '!' || ch == '?') {
			if ((ch = fgetc(fp)) != '.')
				 ++nsents;
.DE
.DM
			else
				while((ch=fgetc(fp)) == '.')
					;
			ungetc(ch, fp);
		}
	}
.DE
.DM
	printf("%d line(s), %d sentence(s).\en",
		nlines, nsents);
}
.DE
.SH "See Also"
.Xr "getc()," getc
.Xr "libc" libc
.br
\*(AS, \(sc7.9.7.1
.br
\*(PX Standard, \(sc8.1
.SH Diagnostics
.B fgetc()
returns EOF at end of file or on error.
