home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: sparky!uunet!zaphod.mps.ohio-state.edu!uwm.edu!linac!uchinews!iitmax!elof.iit.edu!matujos
- From: matujos@elof.iit.edu (Joe Matusiewicz)
- Subject: Re: Problem with string processing.
- Message-ID: <1993Jan6.020420.25829@iitmax.iit.edu>
- Sender: news@iitmax.iit.edu (News)
- Organization: Illinois Institute of Technology, Chicago
- References: <1993Jan2.233446.20833@iitmax.iit.edu> <1993Jan4.191716.11483@eagercon.com>
- Date: Wed, 6 Jan 93 02:04:20 GMT
- Lines: 47
-
-
- I'm the one that had the problem with string processing. First,
- I'd like to thank all of you who mailed me back the answer to my problem.
- All the replys have been extremely helpful. SeSecond, I just wanted to
- post a followup article.
- The problem was most likely my use of calloc with one argument. I
- first used malloc and forgot that calloc required 2 parameters, so I
- accidentally forgot about that. (But some of you might agree with me that
- the stupidest errors are usually the hardest to find). Anyway, here is
- the final copy of my function (which is exactly what many of you suggested):
-
- void add_char_to_str( char *str, int ch )
- {
- while(*str != '\0')
- str++;
- *str++ = ch;
- *str = '\0';
- }
-
- This funtion doesn't have to use dynamic memory allocation at all. It
- simply moves the pointer, str, (which is actually a copy of the pointer, thus
- it is not changed after the fuction is returned) to the end of the string,
- and the character is simply copied to the end. The NULL character is
- appended after that to end the string to end it.
-
- I knew there had to be a simpler way, 'cause there always is.
-
-
-
-
-
-
- P.S.- Thanks for all the additional tips cause I am in the process of learning
- good C prgramming style.
-
-
- Thanx again,
- Joe Matusiewicz.
-
-
-
-
-
-
-
-
-
-