The difference in string and char[], readf() and scanf()

Ivan Kazmenko via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sat Mar 21 08:05:54 PDT 2015


On Saturday, 21 March 2015 at 14:31:20 UTC, Dennis Ritchie wrote:
> In C++ it is fully working:
>
> char s[200005], t[200005];
> scanf("%s%s", s, t);

Indeed.

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.


More information about the Digitalmars-d-learn mailing list