home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!zaphod.mps.ohio-state.edu!wupost!uwm.edu!linac!att!cbnewsk!cbnewsj!att-out!rutgers!mcdhup!src4src!wozzle!alane
- From: alane@wozzle.linet.org (J. Alan Eldridge)
- Newsgroups: comp.lang.c
- Subject: Re: Problem with string processing.
- Message-ID: <Ts3TwB1w165w@wozzle.linet.org>
- Date: 4 Jan 93 03:42:04 GMT
- References: <1993Jan3.050935.1227@news2.cis.umn.edu>
- Organization: Disorganization
- Lines: 24
-
- oleary@staff.tc.umn.edu writes:
-
- > A much better version is:
- >
- > void add_char_to_str(char ch, char *str)
- > {
- > char tmp[2] = {0};
- >
- > *tmp = ch;
- > strcat(str, tmp);
- > }
- >
-
- Oh, dear.
-
- tmp[0] has a 0 in it but tmp[1] is undefined. You are not creating
- a nul-terminated string here.
-
- If you'd said tmp[2]={0,0}; then all would be well on that front.
-
- I guess it's implied that str has enough room to hold the extra character.
-
- alane@wozzle.linet.org (J. Alan Eldridge)
- Fido: The University of Walamaloo 1:272/38.473
-