home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: sparky!uunet!spool.mu.edu!yale.edu!qt.cs.utexas.edu!cs.utexas.edu!convex!constellation!osuunx.ucc.okstate.edu!olesun!gcouger
- From: gcouger@olesun.okstate.edu (Gordon Couger)
- Subject: Re: Problem with string processing.
- Message-ID: <1993Jan4.025351.26173@osuunx.ucc.okstate.edu>
- Sender: news@osuunx.ucc.okstate.edu (USENET News System)
- Nntp-Posting-Host: olesun.agen.okstate.edu
- Organization: Oklahoma State University, Stillwater
- References: <1993Jan2.233446.20833@iitmax.iit.edu> <1993Jan3.194154.1740@data-io.com>
- Date: Mon, 4 Jan 1993 02:53:51 GMT
- Lines: 29
-
- In article <1993Jan3.194154.1740@data-io.com> dietz@parody.Data-IO.COM (Kent Dietz) writes:
- >In article <1993Jan2.233446.20833@iitmax.iit.edu>, matujos@elof.iit.edu (Joe Matusiewicz) writes:
- >|>
- >|> I am having a little problem with string processing. I have been
- >|> programming in C for 6 months, and I just can't figure out the following
- >|> problem:
- >|>
- >|> I need a function to append a character to the end of a string.
-
- #include <strings.h>
-
- char *add_char(char *s, char c)
- {
- char *sp = s;
- while(*sp++)
- ; /* finds end of string and leave pointer for adding char */
- *sp-1 = c;
- *sp = NULL;
- return s;
- }
- This sould do the job and be pretty quick at the same time.
- Of course there must be enough room in the string passed to the function
- for the added char.
- Good luck
- Gordon
-
- Gordon Couger
- AB5Dg Agriculture Engineering Oklahoma State University
- gcouger@olesun.agen.okstate.edu 405-744-6514 day 744-2794 evenings
-