The following piece of code should read each line of the file and operate on it. However, it only reads the first line. Without the for loop it reads the whole file. I honestly have no idea why it's not reading the whole thing.
StreamReader sr = new StreamReader(gridPath);
string line;
char[] lineCh;
char current;
int x, y;
bool north, east, south, west;
x = y = 0;
while ((line = sr.ReadLine()) != null)
{
lineCh = line.ToCharArray();
for (int i = 0; i < lineCh.Length; i++)
{
current = lineCh[i];
north = CheckInput(current);
current = lineCh[++i];
east = CheckInput(current);
current = lineCh[++i];
south = CheckInput(current);
current = lineCh[++i];
west = CheckInput(current);
i++; // Hop over space
grid[x, y] = new GridSquare(north, east, south, west);
x++; // Start next column
}
Console.WriteLine(line);
y++;
}
Without the for loop the following works and prints the whole file:
StreamReader sr = new StreamReader(gridPath);
string line;
char[] lineCh;
char current;
int x, y;
bool north, east, south, west;
x = y = 0;
while ((line = sr.ReadLine()) != null)
{
lineCh = line.ToCharArray();
Console.WriteLine(line);
y++;
}
sr.Close();
CheckInput is as follows:
private bool CheckInput(char c)
{
switch (c)
{
case 'y':
return true;
case 'n':
return false;
default:
return true;
}
}
A sample input file:
nyyn nyyy nyyy nyyy nyyy nnyy
yyyn yyyy yyyy yyyy yyyy ynny
yyyn yyyy yyyy yyyy ynyy nnnn
yyyn yyyy yyyy yyyy ynyy nnnn
yyyn yyyy yyyy yyyy yyyy nnyy
yynn yyny yyny yyny yyny ynny