#include #include #include int main(int argc,char *argv[]) { FILE *f; char to_find[] = "file"; int c; int count = 0; int i; if (argc < 2) { fprintf (stderr, "Ussage: simple fname\n"); return 1; } f = fopen (argv[1], "r"); if (!f) { fprintf (stderr, "Can't open file %s!\n", argv[1]); return 2; } while ((c = fgetc (f)) != EOF) { if (c == to_find[0]) { /* Found first char -> try to find next*/ for (i = 1; i < strlen (to_find); i++) { c = fgetc (f); if (c != to_find [i]) { fseek (f, -i, SEEK_CUR); break; } } if (i == strlen (to_find)) count ++; } } fclose (f); printf ("%d\n", count); return 0; }