Get the next character from a stream: how to use fgetc
#include <stdio.h>
int main ()
{
FILE * file;
char c;
int n = 0;
file=fopen ("my.txt","r");
if (file==NULL)
perror ("Error reading my.txt");
else
{
do {
c = fgetc (file);
if (c == '$')
n++;
} while (c != EOF);
fclose (file);
printf ("File contains %d $.\n",n);
}
return 0;
}
Related examples in the same category