delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1999/09/19/18:08:29

From: Nate Eldredge <neldredge AT hmc DOT edu>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Problem with strcat
Date: Sun, 19 Sep 1999 13:22:04 -0700
Organization: Harvey Mudd College
Lines: 24
Message-ID: <37E545EC.EA685B4A@hmc.edu>
References: <37e52e96 AT news DOT wincom DOT net>
NNTP-Posting-Host: mercury.st.hmc.edu
Mime-Version: 1.0
X-Trace: nntp1.interworld.net 937772562 98221 134.173.45.219 (19 Sep 1999 20:22:42 GMT)
X-Complaints-To: usenet AT nntp1 DOT interworld DOT net
NNTP-Posting-Date: 19 Sep 1999 20:22:42 GMT
X-Mailer: Mozilla 4.61 [en] (X11; U; Linux 2.2.13pre7 i586)
X-Accept-Language: en
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

Kilgore Trout wrote:
> 
> Hello,  I am working on a school assignment and have run into a small
> problem with djgpp.  The purpose of the program is to take a number less
> than 80 typed out in words (such as 'twenty two'), convert it to and
> integer, add seventeen, and convert the integer back into words.  I run into
> a problem if I run the program and input a number greater than or equal to
> 'seventy four'.  I have tried compiling with two other compilers (lcc and
> cc) and the program has worked fine.  I think that the problem may be in the
> line
>   strcat(output_string, integer_to_words(number));
> Any help is greatly appreciated.

The string returned from `integer_to_words' is a constant (since it came
from a literal).  You assign it to `output_string' and then try to
modify it, which is a no-no.  Not only is it constant, but there is no
space for additional characters, so you overwrite something else.

You'll have to create some writable space for it (an array or use
`malloc').
-- 

Nate Eldredge
neldredge AT hmc DOT edu

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019