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