dynamic array of strings

Michael P. baseball.mjp at gmail.com
Tue Dec 30 07:56:08 PST 2008


Jarrett Billingsley Wrote:

> On Mon, Dec 29, 2008 at 10:36 PM, Michael P. <baseball.mjp at gmail.com> wrote:
> > import std.stdio;
> > import std.cstream;
> > void main()
> > {
> >  char[][] names;
> >  char[] currentName;
> >  while( true )
> >  {
> >    din.readf( "%s", &currentName );
> >    if( currentName == "stop" )
> >    {
> >      break;
> >    }
> >    else
> >    {
> names ~= currentName;
> >    }
> >  }
> >  foreach( name; names )
> >  {
> >    writefln( name );
> >  }
> > }
> 
> ~= performs an append.  It adds the given item to the end of the array.

Under 1.036, this does not work.

Input:
michael
is
cool
stop

The output is:
stopeal
st
stop

What seems to be happening is that the letters of stop are added to the word, and if the word is longer than stop, then the rest of the letters of the word are added.
So, I'm not sure if this is a bug or what...
-Michael P.


More information about the Digitalmars-d-learn mailing list