|
|
coherent
fgetc() STDIO Function fgetc()
Read character from stream
#include <stdio.h>
iinntt ffggeettcc(_f_p) FFIILLEE *_f_p;
fgetc reads characters from the input stream fp. In general, it
behaves the same as the macro getc: it runs more slowly than
getc, but yields a smaller object module when compiled.
***** Example *****
This example counts the number of lines and ``sentences'' in a
file.
#include <stdio.h>
main()
{
FILE *fp;
int filename[20];
int ch;
int nlines = 0;
int nsents = 0;
printf("Enter file to test: ");
gets(filename);
if ((fp = fopen(filename,"r")) == NULL) {
printf("Cannot open file %s.\n", filename);
exit(1);
}
while ((ch = fgetc(fp)) != EOF) {
if (ch == '\n')
++nlines;
else if (ch == '.' || ch == '!' || ch == '?') {
if ((ch = fgetc(fp)) != '.')
++nsents;
COHERENT Lexicon Page 1
fgetc() STDIO Function fgetc()
else
while((ch=fgetc(fp)) == '.')
;
ungetc(ch, fp);
}
}
printf("%d line(s), %d sentence(s).\n",
nlines, nsents);
}
***** See Also *****
getc(), STDIO
***** Diagnostics *****
fgetc returns EOF at end of file or on error.
COHERENT Lexicon Page 2
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.