home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!ogicse!news.u.washington.edu!cpac.washington.edu!mcglk
- From: mcglk@cpac.washington.edu (Ken McGlothlen)
- Newsgroups: comp.lang.c
- Subject: Re: Problem with string processing.
- Message-ID: <MCGLK.93Jan5005833@yang.cpac.washington.edu>
- Date: 5 Jan 93 08:58:33 GMT
- Article-I.D.: yang.MCGLK.93Jan5005833
- References: <1993Jan4.022737.19792@kpc.com> <2mqVwB6w165w@cybrspc.UUCP>
- Distribution: usa
- Organization: Dubious.
- Lines: 27
- NNTP-Posting-Host: yang.cpac.washington.edu
-
- Roy M. Silvernail (roy%cybrspc@cs.umn.edu) writes:
- +----------
- | [regarding the C statment: while (*ptr++ = *str++); ]
- |
- | (nice touch, BTW) How does this differ from 'strcpy(ptr, str)' besides the
- | function call overhead?
- +----------
-
- It doesn't. In fact, that's often how strcpy() is implemented.
-
- +----------
- | Assuming a large enough string for the append, and low-high byte ordering,
- | would this work?
- |
- | strcat(str,(char *)&ch);
- +----------
-
- Well, it would work *sometimes*. Remember that strcat() expects two pointers
- to ZERO-TERMINATED strings. If what was stored in ch was immediately followed
- by a zero byte ('\0'), then it *would* work. But ch is stored wherever the
- compiler wants to store it, and it could be followed by *anything*, which means
- that you could get a heck of a lot more characters on the end of str than you
- bargained for.
-
- ---Ken McGlothlen
- mcglk@cpac.washington.edu
- mcglk@cpac.bitnet
-