C examples for stdio.h:getc
function
<cstdio> <stdio.h>
Get character from stream
int getc ( FILE * stream );
Parameter | Description |
---|---|
stream | FILE object |
On success, the character read is returned.
If it reaches the end-of-file, the function returns EOF and sets the eof indicator (feof) of stream.
On other error, the function also returns EOF, but sets its error indicator (ferror) instead.
#include <stdio.h> int main ()//from w ww .j a v a 2 s . c om { FILE * pFile; int c; int n = 0; pFile=fopen ("main.cpp","r"); if (pFile==NULL) { perror("Error opening file"); return -1; } do { c = getc (pFile); if (c == '$') n++; } while (c != EOF); fclose (pFile); printf ("File contains %d$.\n",n); return 0; }