home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!noc.near.net!news.hi.com!calamari.hi.com!not-for-mail
- From: rogers@calamari.hi.com (Andrew Rogers)
- Newsgroups: comp.lang.c
- Subject: Re: Problem with string processing.
- Date: 5 Jan 1993 23:26:08 -0000
- Organization: Hitachi Computer Products, OSSD division
- Lines: 15
- Message-ID: <1idn10INNpvg@calamari.hi.com>
- References: <1993Jan3.050935.1227@news2.cis.umn.edu> <Ts3TwB1w165w@wozzle.linet.org>
- NNTP-Posting-Host: calamari.hi.com
-
- In article <Ts3TwB1w165w@wozzle.linet.org> alane@wozzle.linet.org (J. Alan Eldridge) writes:
- >> char tmp[2] = {0};
- >>
- >> *tmp = ch;
- >> strcat(str, tmp);
- >
- >tmp[0] has a 0 in it but tmp[1] is undefined. You are not creating
- >a nul-terminated string here.
-
- tmp[1] most certainly does have a 0 in it; if the initialization list for
- an array contains fewer elements than the array itself, then the remaining
- array elements are initialized to 0. Check the ANSI spec, or the relevant
- section in K&R.
-
- AWR
-