www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - D doesn't read the first character of a file (reads everything but the

reply Enjoys Math <enjoysmath gmail.com> writes:
DMD32 D Compiler v2.074.1

import std.file;

void main() {
    string bigInput = readText("input.txt");
}

The file is 7 MB of ascii text, don't know if that matters...

Should I upgrade versions?
Jul 17
next sibling parent Nicholas Wilson <iamthewilsonator hotmail.com> writes:
On Tuesday, 18 July 2017 at 02:21:59 UTC, Enjoys Math wrote:
 DMD32 D Compiler v2.074.1

 import std.file;

 void main() {
    string bigInput = readText("input.txt");
 }

 The file is 7 MB of ascii text, don't know if that matters...

 Should I upgrade versions?
I wonder if it thinks there is a BOM and eats it?
Jul 17
prev sibling next sibling parent Sebastien Alaiwan <ace17 free.fr> writes:
On Tuesday, 18 July 2017 at 02:21:59 UTC, Enjoys Math wrote:
 DMD32 D Compiler v2.074.1

 import std.file;

 void main() {
    string bigInput = readText("input.txt");
 }

 The file is 7 MB of ascii text, don't know if that matters...

 Should I upgrade versions?
Could you please share the first 32-bytes (in hex) of your file? Like: $ hexdump -C input.txt
Jul 18
prev sibling parent reply Steven Schveighoffer <schveiguy yahoo.com> writes:
On 7/17/17 10:21 PM, Enjoys Math wrote:
 
 DMD32 D Compiler v2.074.1
 
 import std.file;
 
 void main() {
     string bigInput = readText("input.txt");
 }
 
 The file is 7 MB of ascii text, don't know if that matters...
 
 Should I upgrade versions?
Looking at the implementation of readText, I believe its implementation is not able to trim off the beginning of a file. Be wary of how you look at the result, some tools may "helpfully" hide things (like unprintable characters, or overwrite what has already been displayed when it sees a carriage return). If you can't figure it out yourself, the best thing to do here is to post your exact file somewhere so people can diagnose. Or reproduce with a smaller one, and then post that somewhere. -Steve
Jul 19
parent bauss <jj_1337 live.dk> writes:
On Wednesday, 19 July 2017 at 15:18:00 UTC, Steven Schveighoffer 
wrote:
 On 7/17/17 10:21 PM, Enjoys Math wrote:
 
 DMD32 D Compiler v2.074.1
 
 import std.file;
 
 void main() {
     string bigInput = readText("input.txt");
 }
 
 The file is 7 MB of ascii text, don't know if that matters...
 
 Should I upgrade versions?
Looking at the implementation of readText, I believe its implementation is not able to trim off the beginning of a file. Be wary of how you look at the result, some tools may "helpfully" hide things (like unprintable characters, or overwrite what has already been displayed when it sees a carriage return). If you can't figure it out yourself, the best thing to do here is to post your exact file somewhere so people can diagnose. Or reproduce with a smaller one, and then post that somewhere. -Steve
I'm feeling this. My keyboard sometimes messes up and will send invalid key presses to my OS which often ends up with invalid characters being written in files. When I encounter it I usually open Notepad++ and turn on show all characters which will display unprintable characters, simply allowing me to delete them and have a clean file again.
Jul 19