reading from file

2016-12-13 Thread Namal via Digitalmars-d-learn
Hello, comming from C++, I find it hard to remember and understand how reading from file should be done in D. Especially since I am not very good in functional programming. So I have a file which looks like this: 1,2,3,4 5,6,7,8 9,11,11,12 and so on How could I read it row by row and create

Re: reading from file

2016-12-13 Thread rikki cattermole via Digitalmars-d-learn
On 14/12/2016 4:42 AM, Namal wrote: Hello, comming from C++, I find it hard to remember and understand how reading from file should be done in D. Especially since I am not very good in functional programming. So I have a file which looks like this: 1,2,3,4 5,6,7,8 9,11,11,12 and so on How

Re: reading from file

2016-12-13 Thread bluecat via Digitalmars-d-learn
On Tuesday, 13 December 2016 at 15:42:16 UTC, Namal wrote: Hello, comming from C++, I find it hard to remember and understand how reading from file should be done in D. Especially since I am not very good in functional programming. So I have a file which looks like this: 1,2,3,4 5,6,7,8

Re: reading from file

2016-12-13 Thread Namal via Digitalmars-d-learn
On Tuesday, 13 December 2016 at 16:57:40 UTC, Namal wrote: Sorry if I wasn't clear. The array should be two demensional and each line in text line should be a row in that 2x2 array. Also, it should be saved as an integer.

Re: reading from file

2016-12-13 Thread Namal via Digitalmars-d-learn
Sorry if I wasn't clear. The array should be two demensional and each line in text line should be a row in that 2x2 array.

Re: reading from file

2016-12-13 Thread Ali Çehreli via Digitalmars-d-learn
On 12/13/2016 08:59 AM, Namal wrote: On Tuesday, 13 December 2016 at 16:57:40 UTC, Namal wrote: Sorry if I wasn't clear. The array should be two demensional and each line in text line should be a row in that 2x2 array. Also, it should be saved as an integer. Here is another one: import std.

Re: reading from file

2016-12-13 Thread Ali via Digitalmars-d-learn
On Tuesday, 13 December 2016 at 16:59:17 UTC, Namal wrote: On Tuesday, 13 December 2016 at 16:57:40 UTC, Namal wrote: Sorry if I wasn't clear. The array should be two demensional and each line in text line should be a row in that 2x2 array. Also, it should be saved as an integer. And extendi

Re: reading from file

2016-12-15 Thread KaattuPoochi via Digitalmars-d-learn
On Tuesday, 13 December 2016 at 21:13:26 UTC, Ali wrote: And extending Ali's solution you can actually get the data in to a two dimentional array at compile time and have it in static memory with a small adjustment: static immutable matrix = import("data.txt") .split("\n") .map!(a =>

Re: reading from file

2016-12-15 Thread Ali Çehreli via Digitalmars-d-learn
On 12/15/2016 10:47 PM, KaattuPoochi wrote: > On Tuesday, 13 December 2016 at 21:13:26 UTC, Ali wrote: >> >> And extending Ali's solution you can actually get the data in >> to a two dimentional array at compile time and have it in static >> memory with a small adjustment: >> >> static immutable m

Re: reading from file

2016-12-16 Thread Stefan Koch via Digitalmars-d-learn
On Friday, 16 December 2016 at 06:47:15 UTC, KaattuPoochi wrote: On Tuesday, 13 December 2016 at 21:13:26 UTC, Ali wrote: And extending Ali's solution you can actually get the data in to a two dimentional array at compile time and have it in static memory with a small adjustment: static immu

Re: reading from file

2016-12-16 Thread Ali Çehreli via Digitalmars-d-learn
On 12/15/2016 10:47 PM, KaattuPoochi wrote: > On Tuesday, 13 December 2016 at 21:13:26 UTC, Ali wrote: >> >> And extending Ali's solution you can actually get the data in >> to a two dimentional array at compile time and have it in static >> memory with a small adjustment: >> >> static immutable m

Re: reading from file

2016-12-30 Thread KaattuPoochi via Digitalmars-d-learn
On Friday, 16 December 2016 at 08:03:22 UTC, Ali Çehreli wrote: shared static this() { matrix = (cast(immutable(int[width])*)buffer.ptr)[0..height]; // Make sure we did not copy into matrix assert(cast(void*)matrix.ptr == cast(void*)buffer.ptr); } Thanks Ali, this is neat!!

Error: conversion, reading from file

2009-07-19 Thread Michael P.
I've having some trouble reading from a file. I am trying to read a list of high scores, each on a separate line, like this: 440 0 0 0 0 But with my code, I get an error saying: Error: conversion. Code: //Load high scores char[] file; int[] highScoreList; int nextScore; file = cast(char[])read(

Re: Error: conversion, reading from file

2009-07-19 Thread bearophile
Michael P.: > The output I get is: > 440 > Error: conversion > > The high scores that are printed above is what is in the file. > I am using DMD1.046 with Phobos. Try: import std.string: strip; ... highScoreList ~= toInt(strip(file[0 .. nextScore])); I have never understand the rationale of not

Re: Error: conversion, reading from file

2009-07-19 Thread Michael P.
bearophile Wrote: . > > Try: > import std.string: strip; > ... > highScoreList ~= toInt(strip(file[0 .. nextScore])); > > I have never understand the rationale of not ignoring whitespace inside the > toInt, I think it's an ugly design. > > Bye, > bearophile That didn't work for me. Doing this

Re: Error: conversion, reading from file

2009-07-19 Thread Saaa
> > I have never understand the rationale of not ignoring whitespace inside > the toInt, I think it's an ugly design. > Agreed!