need help

Boris Wang nano.kago at hotmail.com
Mon Apr 24 22:55:21 PDT 2006


You are right, the args array begin from index 0, but

>   foreach( char[] arg; args[0 .. args.length] )

This should not be right, it should be :
    foreach( char[] arg; args[0 .. args.length - 1] )

and more, when i run the followed code:

import std.stdio;

int main( char[][] args )
{
 foreach( char[] arg; args[0 .. args.length - 1 ] )
 {
  printf( "%s ", cast(char*)arg );
 }
}

it even produce a assert:

Error: AssertError Failure hello_my.d(10)


"Regan Heath" <regan at netwin.co.nz> 
??????:ops8jr1mr223k2f5 at nrage.netwin.co.nz...
> On Tue, 25 Apr 2006 11:13:58 +0800, Boris Wang <nano.kago at hotmail.com> 
> wrote:
>> int main( char[][] args )
>> {
>>  foreach( char[] arg; args[1 .. args.length] )
>>  {
>>      printf( "%.*s ", arg );
>>  }
>>
>>  for ( int i = 0; i < args.length; i++ )
>>  {
>>      printf("%.*s ", args[i] );
>>  }
>>
>>  return 0;
>> }
>>
>> The first printf can't display the information, and the second do.
>>
>> I use dmd 0.154, XP SP2.
>
> The first one skips the first arg, to include the first arg use:
>
>   foreach( char[] arg; args[0 .. args.length] )
>   {
>       printf( "%.*s ", arg );
>   }
>
> Apart from that they produce identical output for me.
>
> Regan 





More information about the Digitalmars-d-learn mailing list