read numbers to 2D array

I am trying to read numbers from a text file converted from excel spreadsheet that contains null values. I used "inFile >> myArray[r][c];" but >> seems to ignore NULL. For example if I want to read this (in my txt file there is no char for NULL)
1 NULL 3
4 5 6

it will be stored in the array as
1 3 4
5 6 0

How do I fix it? Any help is appreciated. Thank you so much!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include <iostream>
#include <iomanip>
#include <fstream>
using namespace std;

const int ROWS = 2;
const int COLUMNS = 3;

int main() {
  ifstream inFile;
  int myArray[ROWS][COLUMNS];  
  int r;
  int c;

  inFile.open("test.txt");
  if (!inFile) {
    cout << "Unable to open file";
    exit(1); // terminate with error
  }

  for(r=0; r<ROWS; r++) {
    for(c=0; c<COLUMNS; c++) {
      inFile >> myArray[r][c];
    }
  }

  //print out array
  for(r=0; r<ROWS; r++) {
    for(c=0; c<COLUMNS; c++) {
      cout << myArray[r][c] << " ";
    }
    cout << endl;
  }
  inFile.close();
  return 0;
}
You should open the file in binary mode and get data in an unformatted way:
http://www.cplusplus.com/reference/iostream/istream/get.html
Topic archived. No new replies allowed.