The difference in string and char[], readf() and scanf()
anonymous via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sat Mar 21 13:06:24 PDT 2015
On Saturday, 21 March 2015 at 15:05:56 UTC, Ivan Kazmenko wrote:
> Generate a 100000-character string:
> -----
> import std.range, std.stdio;
> void main () {'a'.repeat (100000).writeln;}
> -----
>
> Try to copy it with D scanf and printf:
> -----
> import std.stdio;
> void main () {
> char [100000] a;
> scanf ("%s", a.ptr);
> printf ("%s\n", a.ptr);
> }
> -----
>
> Only 32767 first characters of the string are actually copied.
That doesn't happen on linux, but I could reproduce it in wine.
Seems to be a bug in the C runtime (snn.lib). I filed an issue:
https://issues.dlang.org/show_bug.cgi?id=14315
More information about the Digitalmars-d-learn
mailing list