// fgetc example: money counter // source: http://www.cplusplus.com/ #include #include int main() { FILE *pFile; char c; int n = 0; pFile=fopen("myfile.txt", "r"); if (pFile==NULL) perror("Error opening file"); else { do { c = fgetc(pFile); if (c == '$') n++; } while (c != EOF); fclose(pFile); printf("The file contains %d dollar sign characters ($).\n",n); } return EXIT_SUCCESS; }