Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- int main(int argc, char* argv[])
- {
- if (argc != 2)
- {
- printf("Usage: %s <filename>\n", argv[0]);
- exit(EXIT_FAILURE);
- }
- FILE* fp;
- int ch = '\0';
- int count = 0;
- char cmp = 0x1a;
- if ((fp = fopen(argv[1], "rb")) == NULL)
- {
- printf("Error reading %s", argv[1]);
- exit(EXIT_FAILURE);
- }
- while (!feof(fp))
- {
- ch = fgetc(fp);
- if (!feof(fp) && ch == EOF) // **
- {
- puts("Terminating program: Error reading from file");
- exit(EXIT_FAILURE);
- }
- if (ch == cmp) count += 1;
- }
- fclose(fp);
- printf("Number of entries: %d\n", count);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment