I'm attempting an application that uses binary data from ".hgt" formatted file. I found a soltuion in C++, but I can't figure out how to translate that solution to C. Each value in the file is type signed short int and there are 1201x1201 values.
const int SIZE = 1201;
signed short int matrix[SIZE][SIZE] = {0};
int main(int argc, const char * argv[])
{
using namespace std;
ifstream file("N49E013.hgt", ios::in|ios::binary);
unsigned char buffer[2];
for (int i = 0; i < SIZE; ++i)
{
for (int j = 0; j < SIZE; ++j)
{
if(!file.read( reinterpret_cast<char*>(buffer), sizeof(buffer) ))
{
cout << "Error reading file!" << endl;
system("PAUSE");
return -1;
}
matrix[i][j] = (buffer[0] << 8) | buffer[1];
}
}