I'm counting the number of lines in a file using feof
as you see below. After that finishes, I need to loop line by line through the same file and do another operation that depends on knowing the number of lines. However, while (!feof(f))
won't run a second time on the same file stream. Is there a way to reset the f
back to the beginning so I can loop through it again?
while (!feof(f))
{
ch = fgetc(f);
if(ch == '\n')
{
lines++;
}
}
while (!feof(f))
{
//need to do an operation that depends on knowing number of lines from first feof but this loop doesn't run because f is at the end
}