Pewnie dla osób obeznanych w C to nie będzie problem ale mnie to przerasta. Mam za zadanie porównać ile razy słowa z jednego pliku (tu keywords.txt) pojawiają się w drugim (tu student.txt) i wyskakują jakieś wartości z sufitu. Pewnie źle przyporządkowuje tekst do zmiennej ale nie jestem pewien.
#include <stdio.h>
#include <string.h>
int main()
{
FILE *fr;
FILE *fs;
FILE *ft;
int r,s;
char bufor[512];
char *spl;
char *spd;
char bufor2[512];
size_t m;
const char *filename = "student.txt";
const char *filename2 = "keywords.txt";
if ((fr = fopen(filename, "r")) == NULL) {
fprintf(stderr, "error: file" "\n");
return 1;
}
if ((fs = fopen(filename2, "r")) == NULL) {
fprintf(stderr, "error: file" "\n");
return 1;
}
while ((r = fscanf(fr, "%*100s")) != EOF)
{
while (feof(fr)==0)
{
fscanf(fr,"%s",bufor);
spd = strtok(bufor, " (){},;-");
while (spd != NULL)
{
spd = strtok(NULL," (){},;-");
}
}
}
while ((r = fscanf(fs, "%*100s")) != EOF)
{
while (feof(fs)==0)
{
fscanf(fs,"%s",bufor2);
spl = strtok(bufor2," (){},;-");
while (spl != NULL)
{
spl = strtok (NULL, " (){},;-");
}
}
}
if (strcmp(bufor,bufor2)==0)
{
m++;
}
if (ferror(fr) != 0) {
fprintf(stderr, "error: read file" "\n");
fclose(fr);
return 1;
}
if (m==1)
{
printf("Keywords appear %lu time", m);
}
else
printf("Keywords appear %lu times", m);
return 0;
}