R
RishiD
Hi,
Trying to read an input file, of characters with spaces and carriage
returns. Basically it is a 20x20 matrix of characters with spaces. I
want to load the information into an two dimensional array.
Cannot seem to figure out how to do like if the read character equals a
space or carriage return, don't put it in the array.
Any ideas?
Thanks,
RishiD
ifstream fin;
string fileName = "sample";
char c;
// Open the file associated with stream fin
fin.open(fileName.c_str());
int x = 0, y = 0;
while (fin.get(c))
{
if (x == 20)
{
x = 0;
y++;
}
// if c != space or crlf ( i know the code below is completely
wrong, just trying to show what i want
if (c != " " || c != "\n")
{ dictArray[x][y] = c;
x++;
}
}
Trying to read an input file, of characters with spaces and carriage
returns. Basically it is a 20x20 matrix of characters with spaces. I
want to load the information into an two dimensional array.
Cannot seem to figure out how to do like if the read character equals a
space or carriage return, don't put it in the array.
Any ideas?
Thanks,
RishiD
ifstream fin;
string fileName = "sample";
char c;
// Open the file associated with stream fin
fin.open(fileName.c_str());
int x = 0, y = 0;
while (fin.get(c))
{
if (x == 20)
{
x = 0;
y++;
}
// if c != space or crlf ( i know the code below is completely
wrong, just trying to show what i want
if (c != " " || c != "\n")
{ dictArray[x][y] = c;
x++;
}
}