Hi,
You can try int size = strlen(buffer);
How do you know what name the buffer has? It's certainly not buffer. It
might be file->__buffer.
Do you know what that code will do if there are no null characters in
the buffer? Do you have any particular reason to believe that there are
any null characters in that buffer? In particular, do you have any
particular reason to believe that there's exactly one null character in
the buffer, and that it's at the end of the buffer?
Le 10/17/2012 11:22 AM, (e-mail address removed) a écrit :
BUFSIZE, #defined in <stdio.h> gives you "the size of the buffer used by
the setbuf function" (7.21.1p3) There's a good chance that this is also
the default buffer size for a file where you've never called setbuf() or
setvbuf(), though that is not guaranteed.
If you can afford to write unportable code, there may be
implementation-specific ways of doing this. If stdio.h defines FILE as a
struct type, you'll often find that it contains a member which gives the
size of the buffer, or one that points at the end of the buffer. I
wouldn't recommend this approach, however.
Why do you need to know?