home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / lang / c / 19287 < prev    next >
Encoding:
Internet Message Format  |  1993-01-06  |  957 b 

  1. Path: sparky!uunet!zaphod.mps.ohio-state.edu!wupost!uwm.edu!linac!att!cbnewsk!cbnewsj!att-out!rutgers!mcdhup!src4src!wozzle!alane
  2. From: alane@wozzle.linet.org (J. Alan Eldridge)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Problem with string processing.
  5. Message-ID: <Ts3TwB1w165w@wozzle.linet.org>
  6. Date: 4 Jan 93 03:42:04 GMT
  7. References: <1993Jan3.050935.1227@news2.cis.umn.edu>
  8. Organization: Disorganization
  9. Lines: 24
  10.  
  11. oleary@staff.tc.umn.edu writes:
  12.  
  13. > A much better version is:
  14. >  
  15. > void add_char_to_str(char ch, char *str)
  16. > {
  17. >         char tmp[2] = {0};
  18. >  
  19. >         *tmp = ch;
  20. >         strcat(str, tmp);
  21. > }
  22. >  
  23.  
  24. Oh, dear.
  25.  
  26. tmp[0] has a 0 in it but tmp[1] is undefined. You are not creating
  27. a nul-terminated string here.
  28.  
  29. If you'd said tmp[2]={0,0}; then all would be well on that front.
  30.  
  31. I guess it's implied that str has enough room to hold the extra character.
  32.  
  33. alane@wozzle.linet.org (J. Alan Eldridge)
  34. Fido: The University of Walamaloo 1:272/38.473
  35.