Jump to page: 1 2
Thread overview
A bug, feature or misunderstanding?
Aug 05, 2003
Gennadi Pais
Aug 05, 2003
Matthew Wilson
Aug 05, 2003
Gennadi Pais
Aug 05, 2003
Matthew Wilson
Aug 05, 2003
Gennadi Pais
Aug 05, 2003
Matthew Wilson
Aug 05, 2003
Matthew Wilson
Aug 06, 2003
Gennadi Pais
Aug 05, 2003
Paul Runde
Aug 05, 2003
Mike Wynn
Sep 12, 2003
Walter
August 05, 2003
Hi All,
during my first trying of the D language in the code:

char[] str = "blah-blah";
str.append(0);
printf ("str is: %s\n", str);

I received compiler error:
.. undefined identifier append

Compiler is: Digital Mars D Compiler Beta v0.68

The tested code is from the D spec.
Thanks.


August 05, 2003
Use %.*s for the string format specifier

"Gennadi Pais" <Gennadi_member@pathlink.com> wrote in message news:bgnqjm$nsb$1@digitaldaemon.com...
> Hi All,
> during my first trying of the D language in the code:
>
> char[] str = "blah-blah";
> str.append(0);
> printf ("str is: %s\n", str);
>
> I received compiler error:
> .. undefined identifier append
>
> Compiler is: Digital Mars D Compiler Beta v0.68
>
> The tested code is from the D spec.
> Thanks.
>
>


August 05, 2003
That's the way I implemented it, but what about the spec?

In article <bgnsh5$pk3$1@digitaldaemon.com>, Matthew Wilson says...
>
>Use %.*s for the string format specifier
>
>"Gennadi Pais" <Gennadi_member@pathlink.com> wrote in message news:bgnqjm$nsb$1@digitaldaemon.com...
>> Hi All,
>> during my first trying of the D language in the code:
>>
>> char[] str = "blah-blah";
>> str.append(0);
>> printf ("str is: %s\n", str);
>>
>> I received compiler error:
>> .. undefined identifier append
>>
>> Compiler is: Digital Mars D Compiler Beta v0.68
>>
>> The tested code is from the D spec.
>> Thanks.
>>
>>
>
>


August 05, 2003
Sorry, I don't understand. In your example you said you done "%s", whereas I'm saying you must use "%.*s". If indeed you used "%.*s" then it's out of my jurisdiction, I'm afraid. ;)

"Gennadi Pais" <Gennadi_member@pathlink.com> wrote in message news:bgnte9$qg8$1@digitaldaemon.com...
> That's the way I implemented it, but what about the spec?
>
> In article <bgnsh5$pk3$1@digitaldaemon.com>, Matthew Wilson says...
> >
> >Use %.*s for the string format specifier
> >
> >"Gennadi Pais" <Gennadi_member@pathlink.com> wrote in message news:bgnqjm$nsb$1@digitaldaemon.com...
> >> Hi All,
> >> during my first trying of the D language in the code:
> >>
> >> char[] str = "blah-blah";
> >> str.append(0);
> >> printf ("str is: %s\n", str);
> >>
> >> I received compiler error:
> >> .. undefined identifier append
> >>
> >> Compiler is: Digital Mars D Compiler Beta v0.68
> >>
> >> The tested code is from the D spec.
> >> Thanks.
> >>
> >>
> >
> >
>
>


August 05, 2003
Gennadi Pais wrote:
> Hi All,
> during my first trying of the D language in the code:
> 
> char[] str = "blah-blah";
> str.append(0);
> printf ("str is: %s\n", str);
> 
> I received compiler error:
> .. undefined identifier append
> 
> Compiler is: Digital Mars D Compiler Beta v0.68
> 
> The tested code is from the D spec.
> Thanks.
> 
> 

From html/d/arrays.html
" Since strings, however, are not 0 terminated in D, when transfering a pointer to a string to C, add a terminating 0:

	str.append(0); "

However, append is not listed as an array property.  Try this:
	
import string;

char[] str = "blah-blah";
printf ("str is: %s\n", toStringz(str));


toStringz appends the terminator.

Paul

August 05, 2003
Please pay attention to the next cut from the D's spec (Arrays section):
______________________________
There are two ways to use printf() with D strings. The first is to add a
terminating 0, and cast the result to a char*:

str.append(0);
printf("the string is '%s'\n", (char *)str);

The second way is to use the precision specifier. The way D arrays are laid out, the length comes first, so the following works:

printf("the string is '%.*s'\n", str);
______________________________
I just want to say that the first described above way is not compiled and failed
with an error (see my first message).

In article <bgo3ds$101p$1@digitaldaemon.com>, Matthew Wilson says...
>
>Sorry, I don't understand. In your example you said you done "%s", whereas I'm saying you must use "%.*s". If indeed you used "%.*s" then it's out of my jurisdiction, I'm afraid. ;)
>
>"Gennadi Pais" <Gennadi_member@pathlink.com> wrote in message news:bgnte9$qg8$1@digitaldaemon.com...
>> That's the way I implemented it, but what about the spec?
>>
>> In article <bgnsh5$pk3$1@digitaldaemon.com>, Matthew Wilson says...
>> >
>> >Use %.*s for the string format specifier
>> >
>> >"Gennadi Pais" <Gennadi_member@pathlink.com> wrote in message news:bgnqjm$nsb$1@digitaldaemon.com...
>> >> Hi All,
>> >> during my first trying of the D language in the code:
>> >>
>> >> char[] str = "blah-blah";
>> >> str.append(0);
>> >> printf ("str is: %s\n", str);
>> >>
>> >> I received compiler error:
>> >> .. undefined identifier append
>> >>
>> >> Compiler is: Digital Mars D Compiler Beta v0.68
>> >>
>> >> The tested code is from the D spec.
>> >> Thanks.
>> >>
>> >>
>> >
>> >
>>
>>
>
>


August 05, 2003
"Gennadi Pais" <Gennadi_member@pathlink.com> wrote in message news:bgnqjm$nsb$1@digitaldaemon.com...
> Hi All,
> during my first trying of the D language in the code:
>
> char[] str = "blah-blah";
> str.append(0);
^^^ see this line

> printf ("str is: %s\n", str);
>
> I received compiler error:
> .. undefined identifier append
^^^ this error is because char[] does not have an append function.

>
> Compiler is: Digital Mars D Compiler Beta v0.68
>
> The tested code is from the D spec.
> Thanks.
>
 try
 char[] str = "blah-blah";

 printf ("str is: %.*s\n", str);  "%.*s" is the D string format spec.

if you want to append to a string use operator ~
str = str ~ "\0";
or str = str ~ \0; /// note no '  ' as you would in C.



August 05, 2003
I may be missing something here - possible - but you seem to be contradicting yourself.

Your first example was

char[] str = "blah-blah";
str.append(0);
printf ("str is: %s\n", str);

Now in this you do neither of

  printf ("str is: %s\n", (char*)str);

or

  printf ("str is: %.*s\n", (char*)str);


Surely this is clear?


"Gennadi Pais" <Gennadi_member@pathlink.com> wrote in message news:bgoe7f$1b2c$1@digitaldaemon.com...
> Please pay attention to the next cut from the D's spec (Arrays section):
> ______________________________
> There are two ways to use printf() with D strings. The first is to add a
> terminating 0, and cast the result to a char*:
>
> str.append(0);
> printf("the string is '%s'\n", (char *)str);
>
> The second way is to use the precision specifier. The way D arrays are
laid out,
> the length comes first, so the following works:
>
> printf("the string is '%.*s'\n", str);
> ______________________________
> I just want to say that the first described above way is not compiled and
failed
> with an error (see my first message).
>
> In article <bgo3ds$101p$1@digitaldaemon.com>, Matthew Wilson says...
> >
> >Sorry, I don't understand. In your example you said you done "%s",
whereas
> >I'm saying you must use "%.*s". If indeed you used "%.*s" then it's out
of
> >my jurisdiction, I'm afraid. ;)
> >
> >"Gennadi Pais" <Gennadi_member@pathlink.com> wrote in message news:bgnte9$qg8$1@digitaldaemon.com...
> >> That's the way I implemented it, but what about the spec?
> >>
> >> In article <bgnsh5$pk3$1@digitaldaemon.com>, Matthew Wilson says...
> >> >
> >> >Use %.*s for the string format specifier
> >> >
> >> >"Gennadi Pais" <Gennadi_member@pathlink.com> wrote in message news:bgnqjm$nsb$1@digitaldaemon.com...
> >> >> Hi All,
> >> >> during my first trying of the D language in the code:
> >> >>
> >> >> char[] str = "blah-blah";
> >> >> str.append(0);
> >> >> printf ("str is: %s\n", str);
> >> >>
> >> >> I received compiler error:
> >> >> .. undefined identifier append
> >> >>
> >> >> Compiler is: Digital Mars D Compiler Beta v0.68
> >> >>
> >> >> The tested code is from the D spec.
> >> >> Thanks.
> >> >>
> >> >>
> >> >
> >> >
> >>
> >>
> >
> >
>
>


August 05, 2003
Correction, the two examples I meant were

   printf ("str is: %s\n", (char*)str);

or

   printf ("str is: %.*s\n", str);




"Matthew Wilson" <matthew@stlsoft.org> wrote in message news:bgp97g$272e$1@digitaldaemon.com...
> I may be missing something here - possible - but you seem to be contradicting yourself.
>
> Your first example was
>
> char[] str = "blah-blah";
> str.append(0);
> printf ("str is: %s\n", str);
>
> Now in this you do neither of
>
>   printf ("str is: %s\n", (char*)str);
>
> or
>
>   printf ("str is: %.*s\n", (char*)str);
>
>
> Surely this is clear?
>
>
> "Gennadi Pais" <Gennadi_member@pathlink.com> wrote in message news:bgoe7f$1b2c$1@digitaldaemon.com...
> > Please pay attention to the next cut from the D's spec (Arrays section):
> > ______________________________
> > There are two ways to use printf() with D strings. The first is to add a
> > terminating 0, and cast the result to a char*:
> >
> > str.append(0);
> > printf("the string is '%s'\n", (char *)str);
> >
> > The second way is to use the precision specifier. The way D arrays are
> laid out,
> > the length comes first, so the following works:
> >
> > printf("the string is '%.*s'\n", str);
> > ______________________________
> > I just want to say that the first described above way is not compiled
and
> failed
> > with an error (see my first message).
> >
> > In article <bgo3ds$101p$1@digitaldaemon.com>, Matthew Wilson says...
> > >
> > >Sorry, I don't understand. In your example you said you done "%s",
> whereas
> > >I'm saying you must use "%.*s". If indeed you used "%.*s" then it's out
> of
> > >my jurisdiction, I'm afraid. ;)
> > >
> > >"Gennadi Pais" <Gennadi_member@pathlink.com> wrote in message news:bgnte9$qg8$1@digitaldaemon.com...
> > >> That's the way I implemented it, but what about the spec?
> > >>
> > >> In article <bgnsh5$pk3$1@digitaldaemon.com>, Matthew Wilson says...
> > >> >
> > >> >Use %.*s for the string format specifier
> > >> >
> > >> >"Gennadi Pais" <Gennadi_member@pathlink.com> wrote in message news:bgnqjm$nsb$1@digitaldaemon.com...
> > >> >> Hi All,
> > >> >> during my first trying of the D language in the code:
> > >> >>
> > >> >> char[] str = "blah-blah";
> > >> >> str.append(0);
> > >> >> printf ("str is: %s\n", str);
> > >> >>
> > >> >> I received compiler error:
> > >> >> .. undefined identifier append
> > >> >>
> > >> >> Compiler is: Digital Mars D Compiler Beta v0.68
> > >> >>
> > >> >> The tested code is from the D spec.
> > >> >> Thanks.
> > >> >>
> > >> >>
> > >> >
> > >> >
> > >>
> > >>
> > >
> > >
> >
> >
>
>


August 06, 2003
Dear All,
thank for the explanation how can I print a string out, but if you will pay
attention I didn't ask about how to (I've found some different ways), but the
issue was the compilation error because of lack of the array's <append> method.
I think the clear and right spec is exactly what the new language need. So I
want to ask somebody who has permission to edit D's documentation to fix that
over there.

In article <bgpb2f$28tu$1@digitaldaemon.com>, Matthew Wilson says...
>
>Correction, the two examples I meant were
>
>   printf ("str is: %s\n", (char*)str);
>
>or
>
>   printf ("str is: %.*s\n", str);
>
>
>
>
>"Matthew Wilson" <matthew@stlsoft.org> wrote in message news:bgp97g$272e$1@digitaldaemon.com...
>> I may be missing something here - possible - but you seem to be contradicting yourself.
>>
>> Your first example was
>>
>> char[] str = "blah-blah";
>> str.append(0);
>> printf ("str is: %s\n", str);
>>
>> Now in this you do neither of
>>
>>   printf ("str is: %s\n", (char*)str);
>>
>> or
>>
>>   printf ("str is: %.*s\n", (char*)str);
>>
>>
>> Surely this is clear?
>>
>>
>> "Gennadi Pais" <Gennadi_member@pathlink.com> wrote in message news:bgoe7f$1b2c$1@digitaldaemon.com...
>> > Please pay attention to the next cut from the D's spec (Arrays section):
>> > ______________________________
>> > There are two ways to use printf() with D strings. The first is to add a
>> > terminating 0, and cast the result to a char*:
>> >
>> > str.append(0);
>> > printf("the string is '%s'\n", (char *)str);
>> >
>> > The second way is to use the precision specifier. The way D arrays are
>> laid out,
>> > the length comes first, so the following works:
>> >
>> > printf("the string is '%.*s'\n", str);
>> > ______________________________
>> > I just want to say that the first described above way is not compiled
>and
>> failed
>> > with an error (see my first message).
>> >
>> > In article <bgo3ds$101p$1@digitaldaemon.com>, Matthew Wilson says...
>> > >
>> > >Sorry, I don't understand. In your example you said you done "%s",
>> whereas
>> > >I'm saying you must use "%.*s". If indeed you used "%.*s" then it's out
>> of
>> > >my jurisdiction, I'm afraid. ;)
>> > >
>> > >"Gennadi Pais" <Gennadi_member@pathlink.com> wrote in message news:bgnte9$qg8$1@digitaldaemon.com...
>> > >> That's the way I implemented it, but what about the spec?
>> > >>
>> > >> In article <bgnsh5$pk3$1@digitaldaemon.com>, Matthew Wilson says...
>> > >> >
>> > >> >Use %.*s for the string format specifier
>> > >> >
>> > >> >"Gennadi Pais" <Gennadi_member@pathlink.com> wrote in message news:bgnqjm$nsb$1@digitaldaemon.com...
>> > >> >> Hi All,
>> > >> >> during my first trying of the D language in the code:
>> > >> >>
>> > >> >> char[] str = "blah-blah";
>> > >> >> str.append(0);
>> > >> >> printf ("str is: %s\n", str);
>> > >> >>
>> > >> >> I received compiler error:
>> > >> >> .. undefined identifier append
>> > >> >>
>> > >> >> Compiler is: Digital Mars D Compiler Beta v0.68
>> > >> >>
>> > >> >> The tested code is from the D spec.
>> > >> >> Thanks.
>> > >> >>
>> > >> >>
>> > >> >
>> > >> >
>> > >>
>> > >>
>> > >
>> > >
>> >
>> >
>>
>>
>
>


« First   ‹ Prev
1 2