home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / lang / c / 19185 < prev    next >
Encoding:
Text File  |  1993-01-04  |  1.5 KB  |  42 lines

  1. Newsgroups: comp.lang.c
  2. Path: sparky!uunet!spool.mu.edu!yale.edu!qt.cs.utexas.edu!cs.utexas.edu!convex!constellation!osuunx.ucc.okstate.edu!olesun!gcouger
  3. From: gcouger@olesun.okstate.edu (Gordon Couger)
  4. Subject: Re: Problem with string processing.
  5. Message-ID: <1993Jan4.025351.26173@osuunx.ucc.okstate.edu>
  6. Sender: news@osuunx.ucc.okstate.edu (USENET News System)
  7. Nntp-Posting-Host: olesun.agen.okstate.edu
  8. Organization: Oklahoma State University, Stillwater
  9. References: <1993Jan2.233446.20833@iitmax.iit.edu> <1993Jan3.194154.1740@data-io.com>
  10. Date: Mon, 4 Jan 1993 02:53:51 GMT
  11. Lines: 29
  12.  
  13. In article <1993Jan3.194154.1740@data-io.com> dietz@parody.Data-IO.COM (Kent Dietz) writes:
  14. >In article <1993Jan2.233446.20833@iitmax.iit.edu>, matujos@elof.iit.edu (Joe Matusiewicz) writes:
  15. >|> 
  16. >|>    I am having a little problem with string processing.  I have been
  17. >|> programming in C for 6 months, and I just can't figure out the following
  18. >|> problem:
  19. >|> 
  20. >|>    I need a function to append a character to the end of a string.
  21.  
  22. #include <strings.h>
  23.  
  24. char *add_char(char *s, char c)
  25.    {
  26.    char *sp = s;
  27.    while(*sp++)
  28.       ;  /* finds end of string and leave pointer for adding char */
  29.    *sp-1 = c; 
  30.    *sp = NULL;
  31.    return s;
  32.    }
  33. This sould do the job and be pretty quick at the same time.
  34. Of course there must be enough room in the string passed to the function
  35. for the added char. 
  36. Good luck
  37. Gordon
  38.  
  39. Gordon Couger
  40. AB5Dg   Agriculture Engineering Oklahoma State University
  41. gcouger@olesun.agen.okstate.edu 405-744-6514 day 744-2794 evenings   
  42.