On Sun, Jun 8, 2008 at 12:56 PM, Bill Cunningham <[EMAIL PROTECTED]> wrote:
> So Bret buffers don't hold the null string literal terminator ? I don't > know I've never really thought about it. I know strlen doesn't include it. I > could've written a little code giving me the strlen of the string but if you > know I'll just ask you. char arrarys will not by default include '\0' then? > What about puts ? No, a char buffer (either an array or a pointer) does not automatically have '\0'. You have to take that into account when allocating memory. If you want a 10 char string, you need to allocate 11. If you forget the '\0', some string operations will keep reading past the end and cause a buffer overflow and other dangerous things. C doesn't have a built-in string type, by definition strings are statically allocated arrays of char or a pointer to a chunk of memory that contains an array of char. C strings are a pain and can be very confusing. My advice? Don't bother with C unless you have an absolute need to and use C++ which comes with an easy to use standard string class and you don't have to worry about null terminators and the other silliness that comes with string processing in C. -- Brett ------------------------------------------------------------ "In the rhythm of music a secret is hidden; If I were to divulge it, it would overturn the world." -- Jelaleddin Rumi
