I'm working on a C++ project for school and I am trying to write a matrix from a text file into an array. There are negative numbers and two 5x5 matrices in the source data. I keep getting different characters (╧ or =) instead of the negative number:
void main()
{
char c;
char nbRow , nbCol;
int location = 0;
int MatrixArray[10][10];
int negNbr;
int k = 0;
int l = 0;
cin.get(c);
nbRow = c;
cout << "Number of rows: " << nbRow << endl;
cin.get(c);
cin.get(c);
nbCol = c;
cout << "Number of columns: " << nbCol << endl;
while (!cin.eof())
{
cin.get(c);
//cout << (int)c << endl;
if (!isblank(c) && (isdigit(c) || c == 45))
{
cout << c << " | test1 " << " | ";
if (c == 45)
{
cin.get(c);
negNbr = (char)c;
negNbr = negNbr * -1;
cout << (char)negNbr;
MatrixArray[k][l] = (char)negNbr;// *-1;
}
else //if (isdigit(c))
{
MatrixArray[k][l] = (char)c;
}
cout << " |test2 " << k << l << "| " << (char)MatrixArray[k][l] << endl;
if (l == 4)
{
k++;
l = 0;
}
else l++;
}
}