Path: utzoo!mnetor!uunet!husc6!think!barmar From: barmar@think.COM (Barry Margolin) Newsgroups: comp.arch Subject: Re: Null-terminated C strings Message-ID: <14116@think.UUCP> Date: 21 Dec 87 16:38:35 GMT References: <261@ivory.SanDiego.NCR.COM> <164@sdeggo.UUCP> <174@quick.COM> Sender: usenet@think.UUCP Reply-To: barmar@sauron.think.com.UUCP (Barry Margolin) Organization: Thinking Machines Corporation, Cambridge, MA Lines: 24 In article <174@quick.COM> srg@quick.COM (Spencer Garrett) writes: >2) Having a CHARACTER to mark the end of a string is ever so much >more convenient and efficient than having to compare lengths all the >time The problem with this is that you must reserve a character. I've had trouble with terminal emulators on machines whose keyboard-reading system call returns 0 to indicate that no data is available, but 0 is also the code for Control-@. This type of problem occurs in file reading, too. If you are reading a binary file, or perhaps a file of keyboard operations (perhaps you recorded an Emacs session), as characters the NULL character can no longer be used as a string terminator; such files can contain any 8-bit code, so NO 8-bit character can be used as a termination indicator. Strings with lengths ALWAYS work. --- Barry Margolin Thinking Machines Corp. barmar@think.com seismo!think!barmar