Re: Null-terminated strings: the final analysis.
- From: Harald van Dijk <truedfx@xxxxxxxxx>
- Date: Sun, 12 Apr 2009 20:52:12 +0000 (UTC)
On Sun, 12 Apr 2009 13:32:39 -0700, Keith Thompson wrote:
On the systems I use, if I write a '\a' character (ASCII BEL) to a text
file, I can reasonably expect to see a '\a' character when I read it
back. The same is not true of '\0' if I use fgets() to read it (though
I think can see the '\0' if I use fgetc()).
If you use fgets, you can see any '\0' that you had previously written,
but you've got to be careful to make sure you don't treat it as a
terminator. You cannot reliably determine whether the '\0' is a
terminator, but you can reliably detect many instances where it is not: if
the bytes following '\0' have been altered by fgets, then they were read
from the file. If the bytes following '\0' have not been altered by fgets,
then you cannot be sure where they came from.
.
- Follow-Ups:
- Re: Null-terminated strings: the final analysis.
- From: Flash Gordon
- Re: Null-terminated strings: the final analysis.
- References:
- Re: Null-terminated strings: the final analysis.
- From: Tony
- Re: Null-terminated strings: the final analysis.
- From: Mark McIntyre
- Re: Null-terminated strings: the final analysis.
- From: Mark Wooding
- Re: Null-terminated strings: the final analysis.
- From: CBFalconer
- Re: Null-terminated strings: the final analysis.
- From: Joe Wright
- Re: Null-terminated strings: the final analysis.
- From: Mark Wooding
- Re: Null-terminated strings: the final analysis.
- From: Mark McIntyre
- Re: Null-terminated strings: the final analysis.
- From: Keith Thompson
- Re: Null-terminated strings: the final analysis.
- Prev by Date: Re: Null-terminated strings: the final analysis.
- Next by Date: Re: Portability regarding sizeof() function
- Previous by thread: Re: Null-terminated strings: the final analysis.
- Next by thread: Re: Null-terminated strings: the final analysis.
- Index(es):
Relevant Pages
|