[Solved] C# Read int numbers to array [closed]


Instead of using str.Read() which would require you to read single characters (or a buffer that you specified), try using str.Readline() to read a single line for each iteration of i.

public void readFromFile()
{
    StreamReader str = new StreamReader("SUDOKU.txt");
    for (int i = 0; i < 9; ++i)
    {
        string[] lineNumbers = str.ReadLine().Split(' ');
        for (int j = 0; j < 9; ++j)
        {
            puzzle[i, j] = Convert.ToInt32(lineNumbers[j]);
        }
    }
    str.Close();
}

This reads a single line at a time (each iteration of i), splits the line into lineNumbers by separating the current line by space characters. Each number on the current line can then be accessed by lineNumbers[j] within your inner loop (each iteration of j).

solved C# Read int numbers to array [closed]