OK once again, pointers are causing me headaches
I'm trying to get a word from a file, and write that into a buffer. The buffer is malloced like so:
and the function called:Code:char *buf = malloc( INIT * sizeof(char) );
where getword has the definition:Code:while ( getword(buf, INIT) != EOF )
Then the buffer is realloced inside the getword function, if necessary.Code:int getword(char *W, int size)
The problem is, if the realloc is done, the W returned is correct, but the buf recieved is junk. I assumed that by reallocing W, i was reallocing the same pointer as buf. Is this not correct?Code:size *= 2; W = realloc(W, size * sizeof(char) );