memory leak

This is a discussion on memory leak within the C Programming forums, part of the General Programming Boards category; i wrote this function to scan a word from a file:
char * fgetword(FILE *f)
{
char *word,*tmp,c;
int i ...

ok, first problem is solved. i oversaw a missing free (stupid i know).

but how can i manage to allocate exactly as much memory for my word as it needs? (if not knowing how long this word will gona be) I thought about resizing the allocated memory everytime i read a char. but how could i do that?

but when the memory block is too big, realloc moves it position and &(*myptr)-&(*p) neither is the right size nor is p pointing to the beginning of the "string". why? (if i count the size of &(*myptr)-&(*p) it is during the loops: 1,2,3,4,5,6,7,8,9,6474)

Also, (1) you cannot free memory and then return it from a function as a valid pointer! (2) You are wasting valuable resources/time by requesting/unrequesting chunks of data like that.
I have a suggestion: Use a "static" buffer that is created only once and return a pointer to the current position.