while(fgets(buffer,sizeof buffer,f))

You don't know difference between array and pointer.
sizeof cannot tell you the sizeof the memory block that pointer is pointing.
It just tells you sizeof...