Strange behavior of read file

Paul Jurczak pauljurczak at yahoo.com
Tue Aug 27 10:14:22 PDT 2013


Correction to my initial post:

I oversimplified the code example by snipping too much of 
context. Here is an example, which fails both on Windows and 
Linux:

module main;

import std.stdio, std.file, std.string, std.algorithm, std.range, 
std.datetime, std.conv, std.typetuple;

int e67_1(string fileName = r"67.txt") {
    // Read triangle numbers from file.
    int[][] cell;

    foreach (y, line; splitLines(cast(char[]) read(fileName))) {
       auto row = new int[y+1];

       foreach (x, token; split(line))
          row[x] = to!int(token);

       cell ~= row;
    }

    // Compute maximum value partial paths ending at each cell.
    foreach (y; 1..cell.length) {
       cell[y][0] += cell[y-1][0];

       foreach (x; 1..y)
          cell[y][x] += max(cell[y-1][x-1], cell[y-1][x]);

       cell[y][y] += cell[y-1][y-1];
    }

    // Return the maximum value terminal path.
    return cell[$-1].reduce!max;
}


void main()
{
    try {
       writeln(e67_1);
    }
    catch (Exception e) {
       writeln(e);
    }
}

Here is the message on Linux:

std.file.FileException at std/file.d(219): 67.txt: No such file or 
directory
----------------
./main(void[] std.file.read(const(char[]), ulong)+0x87) [0x4c5b2b]
./main(int main.e67_1(immutable(char)[])+0x41) [0x4805a9]
./main(_Dmain+0x56) [0x4807de]
./main(extern (C) int rt.dmain2._d_run_main(int, char**, extern 
(C) int function(char[][])*).void runMain()+0x18) [0x4b8e60]
./main(extern (C) int rt.dmain2._d_run_main(int, char**, extern 
(C) int function(char[][])*).void tryExec(scope void 
delegate())+0x2a) [0x4b8992]
./main(extern (C) int rt.dmain2._d_run_main(int, char**, extern 
(C) int function(char[][])*).void runAll()+0x40) [0x4b8eb0]
./main(extern (C) int rt.dmain2._d_run_main(int, char**, extern 
(C) int function(char[][])*).void tryExec(scope void 
delegate())+0x2a) [0x4b8992]
./main(_d_run_main+0x1ae) [0x4b894e]
./main(main+0x17) [0x4b879b]
/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf5) 
[0x7ff2929ccea5]

Again, the file requested exists. I test that by adding other 
functions (from my initial post) to the code above.


More information about the Digitalmars-d-learn mailing list