I would like to print the words to the screen, which length's is shorter than the average length of the all words which are in a text file.
My text file : in1feladat.txt
words are here:
negy
ötötö
hathat
hetheth
nyolcnyo
so the average length is 6 (4+5+6+7+8 / 5 = 6) so the program should write to the screen : negy ötötö
my txt is located next to the main.c so its in the project folder. C:\Users\lszima\Desktop\proggg\fannikahelp\in1feladat.txt
codeblocks returns with the following error: Process terminated with status -1073741819 (0 minute(s), 1 second(s))
debug : Program received signal SIGSEGV, Segmentation fault. 0x4013dd line 16 which is the while(!feof(f1)
Can somebody help me out, what did i do wrong?
Thank you very much.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
FILE *f1=fopen("c:\users\lszima\desktop\proggg\fannikahelp\in1feladat.txt","r");
double atlag=0;
int sum=0;
int t[10];
int i=0;
char szo[100];
while(!feof(f1)){
// szavak hossza belerakása a tömbbe
//fscanf(f1,"%s",szo);
fgets(szo,100,f1);
t[i]=strlen(szo);
i++;
}
int j=0;
for (j=0;j<i;j++)
sum+=t[j];
atlag=(double)sum/(i+1);
printf("atlag= %lf",atlag);
fclose(f1);
FILE *f1=fopen("c:\users\lszima\desktop\proggg\fannikahelp\in1feladat.txt","r");
char szavak[100];
while(!feof(f2)){
//fscanf(f2,"%s",szavak);
fgets(szavak,100,f2);
if(strlen(szavak)<atlag)
printf("%s ",szavak);
}
return 0;
}