www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/02/27/04:05:41

From: G DOT DegliEsposti AT ads DOT it
To: djgpp AT delorie DOT com
Message-ID: <C12565B8.0030A647.00@vega.ads.it>
Date: Fri, 27 Feb 1998 10:03:03 +0100
Subject: Re: Strings in DJGPP
Mime-Version: 1.0




>i was writing a cpp program.  in this program i marked a variable as:
>
>char* data
>
>i then made this a string of [30]:
>
>{
>size = strlen(init);

this can be the problem, see below.

>data = new char[size + 1];
>assert(data != 0);
>strcpy(data, init);
>}
>
>where "init" was just nothing  ""  ... i'm just initializing here...
if init is "" then strlen(init) is 0. This means that data is initializad
by new char[0 + 1] and not 30.

[...]
>        right.data[i++] = input.get();                 // or whatever
"/@$#!@#%" ...
...when i > 0 where is input.get() stored?

Data is written into some memory not belonging to right.data

>okay, the problem lies in the output!  when i print the output to output
stream (stdout or >file)  i only get 4 chars!!! and an upside down U... i
guess its an omega??? i don't
>really know...

This could be because "<<" reads starting from the pointer you give and
then
continues until a '\0' is found, reading whatever ther is after the end of
your
string (or what you think is the end of your string :-)

Try to allocate a fixed amount of chars and see if there are some
differences

ciao
  Giacomo


- Raw text -


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