January 25, 2004 Bug? | ||||
---|---|---|---|---|
| ||||
import std.c.stdio; import std.string; int main(char[][] args) { char[] bla = "BLA"; printf(bla[0..1]); return 0; } Prints "BLA" . shouldn't it print "B" ? If I replace it with printf(bla[0..1] ~ \n); then it is OK (it prints "B") I am using v838 Cheers, Luigi |
January 25, 2004 Re: Bug? | ||||
---|---|---|---|---|
| ||||
Posted in reply to 0x4e71 | 0x4e71 wrote:
> import std.c.stdio;
> import std.string;
>
> int main(char[][] args)
> {
> char[] bla = "BLA";
> printf(bla[0..1]);
> return 0;
> }
>
> Prints "BLA" . shouldn't it print "B" ?
>
> If I replace it with printf(bla[0..1] ~ \n); then it is OK (it prints "B")
> I am using v838
>
> Cheers,
> Luigi
>
Not a bug. D strings aren't necessarily null-terminated. printf, being a C function, expects a null-terminated string.
printf(toStringz(bla[0..1]));
or
printf(bla[0..1] ~ \0);
|
Copyright © 1999-2021 by the D Language Foundation