I can only guess what you're writing about. Do you want to know
the length of a string that you're going to read in before you
actually have read it in in order to allocate enough memory for
the string? If that's the case then you're unfortunately out
of luck. You can't know the length of a string before you have
read it in completely. Predicting the future is simply hard to
do...
What you normally do in cases where you want to read in a string
of arbitrary length which you want to store in dynamically allo-
cated memory is to start by allocating some amount of memory
(e.g. 128 bytes, but any other non-zero guess will also do).
Then you read in not more than fits into that amount of memory.
If you find that the whole string already fits into this buffer
you're done. Otherwise you increase the size of your buffer by
allocating more memory using realloc() and con- tinue to read
until also this increased buffer is full or you reached the end
of the string. In case you still didn't reach the end you again
allocate more memory with realloc() and continue as above. In
the end you have ethe whole string stored in allocated memory
if you haven't run out of memory before.
Some friendly people have already taken the time to write a
function just doing this, see e.g. the ggets() function by
C.B. Falconer:
http://cbfalconer.home.att.net/download/ggets.zip