Dynamic memory
anonymous via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Tue Jul 28 09:24:38 PDT 2015
On Tuesday, 28 July 2015 at 16:09:46 UTC, Binarydepth wrote:
> Here is what I'm trying to do :
>
> import std.stdio : readf, writef;
> void main() {
> int[2][] nam;
> int num;
> readf(" %d", &num);
> nam.length = num;
> foreach(nim; 0..num) {
> readf(" %d %d", &nam[0][num], &nam[1][num]);
> }
> foreach(nim; 0..num) {
> writef(" %d %d\n", &nam[0][num], &nam[1][num]);
> }
> }
In addition to Adam:
there are typos (num instead of nim) - since num is the array
length and the indices are 0-based, num is out of bounds...
foreach(nim; 0..num) {
readf(" %d %d", &nam[nim][0], &nam[nim][1]);
}
foreach(nim; 0..num) {
writef(" %d %d\n", nam[nim][0], nam[nim][1]);
}
works fine.
More information about the Digitalmars-d-learn
mailing list