From: G DOT DegliEsposti AT ads DOT it To: djgpp AT delorie DOT com Message-ID: Date: Fri, 27 Feb 1998 10:03:03 +0100 Subject: Re: Strings in DJGPP Mime-Version: 1.0 Content-type: text/plain; charset=us-ascii Precedence: bulk >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