digitalmars.D.learn - Reading formatted file
Hello World! I am new at D, I'm making a sudoku solver in D, I wanted to add the option to read sudoku from a .txt file. I am finding a bit confusing how to open, read and close files in D. I am trying to mimic the C code: FILE *f_in; f_in=fopen("sudoku.txt"); if (f_in==NULL){ exit(1); } while(ch=fgetc() != EOF){ //convert char to int... put char in matrix... } could you help me? thank you, I appreciate it! -Tabamon.
Jun 27 2019
On Thursday, 27 June 2019 at 13:31:23 UTC, Tabamon wrote:I am new at D, I'm making a sudoku solver in D, I wanted to add the option to read sudoku from a .txt file.1) try to google "dlang read text file", most probably 1,2,3 link will help to u. 2) https://dlang.org/library/std/file/read_text.html string content = readText( fileName );
Jun 27 2019
On Thursday, 27 June 2019 at 13:52:43 UTC, a11e99z wrote:On Thursday, 27 June 2019 at 13:31:23 UTC, Tabamon wrote: 1) try to google "dlang read text file", most probably 1,2,3 link will help to u. 2) https://dlang.org/library/std/file/read_text.html string content = readText( fileName );3) for matrix reading better to use byLine() https://dlang.org/library/std/stdio/file.by_line.html (see the samples below)
Jun 27 2019