Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- int main(int argc, const char **argv) {
- if (argc != 3) {
- exit(1);
- }
- FILE *in = fopen(argv[1], "r");
- if (!in) {
- exit(1);
- }
- long count = 0;
- for (char buf[BUFSIZ]; fgets(buf, BUFSIZ, in);) {
- for (char *p = buf, *q; p < buf + BUFSIZ && (q = strstr(p, argv[2]));
- ++count, p = q + 1) {
- ;
- }
- }
- fclose(in);
- printf("%s is %ld.\n", argv[2], count);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement