Mega Code Archive

 
Categories / C / Code Snippets
 

Get the next character how to use getc

#include <stdio.h> int main () { FILE *file; char c; int j = 0; file = fopen("myfile.txt", "r"); if (file==NULL) perror ("Error reading file"); else { do { c = getc (file); if (c == '$') j++; } while (c != EOF); fclose (file); printf ("myfile.txt contains %d $.\n",j); } return 0; }