Witam
Mam problem z odszukaniem danej frazy pliku tekstowym. Proszę o pomoc. Załączam dany plik tekstowy.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char z;
int linie, znaki, n, s, i;
int main(void)
{
FILE* file;
if ((file = fopen("stokes.txt", "r")) == NULL) {
puts("Nie udalo sie otworzyc pliku");
return 1;
}
znaki = 0;
linie = 1;
while (feof(file) == 0) {
fscanf(file, "%c", &z);
printf("%c", z);
if (z != 10) {
znaki++;
}
if (z == 10) {
linie++;
}
}
printf("\n\n");
printf("Liczba linijek tekstu = %d\n", linie);
printf("Liczba znakow w tekscie = %d\n", znaki);
n = 0;
s = 0;
rewind(file);
char temporary[20];
char* pointer;
while (feof(file) == 0) {
i = 0;
do {
fscanf(file, "%c", &z);
i++;
} while (z != ' ');
pointer = fgets(temporary, i, file);
printf("%c", temporary[2]);
if (strstr(temporary, "st")) {
n++;
}
else {
continue;
}
if (strstr(temporary, "ST")) {
n++;
}
else {
continue;
}
if (strstr(temporary, "sT")) {
n++;
}
else {
continue;
}
if (strstr(temporary, "Stokes")) {
n++;
s++;
}
else {
continue;
}
fseek(file, i, 1);
}
printf("Wystapienie danych dwoch znakow = %d\n", n);
printf("Wystapienie slowa Stokes = %d\n", s);
fclose(file);
return 0;
}