Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- int main(void) {
- FILE *in = fopen("a.txt", "r");
- const char *s = "ab";
- char buf[BUFSIZ];
- int c = 0;
- while (fgets(buf, BUFSIZ - 1, in)) {
- char *p = buf;
- while (1) {
- char *p2 = strstr(p, s);
- if (p2 != NULL) c++;
- else break;
- p = p2 + strlen(s);
- }
- }
- fclose(in);
- printf("%d\n", c);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement