soluces/c/semaine-4/vie-privee/main.c
2023-11-22 23:07:21 +01:00

34 lines
588 B
C

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(void) {
FILE *file;
char text[10000], *word = "vie privée", *found;
int n = 0;
file = fopen("cypherpunk.txt", "r");
if (file == NULL) {
printf("failed reading file");
return EXIT_FAILURE;
}
while (fgets(text, sizeof(text), file) != NULL) {
found = strstr(text, word);
while (found != NULL) {
printf("found at position %ld\n", (long)(found - text) + 1);
n++;
found = strstr(found + 1, word);
}
}
printf("%d", n);
fclose(file);
return EXIT_SUCCESS;
}