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

Dennis Ritchie via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sat Mar 21 01:37:58 PDT 2015


Hi,
Tell me, please, why this code works correctly always:

import std.stdio;

int n;
readf("%s\n", &n);

string s, t;
readf("%s\n%s\n", &s, &t);

And this code works correctly is not always:

import std.stdio;

readf("%s\n", &n);

char[200010] s, t;
scanf("%s%s", s.ptr, t.ptr);

Data is entered only in this format (n - the length of strings 
str1 and str2, 1 <= n <= 200000; only lowercase letters):

n
str1
str2

For example:

5
cater
doger


More information about the Digitalmars-d-learn mailing list