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

Dennis Ritchie via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sat Mar 21 09:34:42 PDT 2015


On Saturday, 21 March 2015 at 15:05:56 UTC, Ivan Kazmenko wrote:
> 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.

And why in D copied only the first 32767 characters of the 
string? I'm more days couldn't understand what was going on...

> 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.

Thank you very much.


More information about the Digitalmars-d-learn mailing list