I got this code:
while(!feof(fp))
{
fgets(line,20,fp);
puts(line);
}
fp
is this file:
prova1
prova2
prova3prova4
prova5
The fact is: if the count parameter of the fgets function it's a lower number than 10 it works everything ok, but if it's greater it gives me a stack smashing detected
error.
I think it's because I'm trying to read after EOF, but why when I'm trying to read just after it works (like 8 characters per line) but when I put a count parameter of like 20 it gives me an error?
NB: the last line "prova5" is formed by 6 characters plus the '\0' I think, so 7. Why with 8 it's ok and it's not with 20?
EDIT: I'm sorry, I forgot to include this declaration:
char line[] = "";