我在 Windows 上使用 GCC 编译器(代码块),我得到的数据来自 UNIX 机器,所以它都是大端的。我必须先把它换成小端序,然后才能使用它。我会被拦住,但我无法让它发挥作用。使用
temp = ntohl(fileBuf[N*i+j]);
或者
_byteswap_ulong(fileBuf[N*i+j]);
只返回零。我知道一个事实是不正确的。
传入的数据只是一串 32 位整数(美国部分地区的海拔数据)。任何帮助是极大的赞赏
编辑:这里很新,我不确定代码是否有用
typedef unsigned char BYTE
int main()
{
long int temp;
int i,j;
ofstream myFile;
myFile.open("fixed4.txt");
const char *filePath = "input2";
BYTE *fileBuf;
FILE *file = NULL;
if ((file = fopen(filePath, "rb"))==NULL)
cout<< "File could not be opened successfully" << endl;
else
cout << "File Opened successfully" << endl;
long fileSize = getFileSize(file);
fileBuf = new BYTE[fileSize];
//BYTE *flipped;
//flipped = new BYTE[fileSize];
fread(fileBuf, fileSize, 4, file);
for (i=0; i<N; i+=1){
for (j=0; j<N; j+=1){
temp = _byteswap_ulong(fileBuf[N*i+j]);
grid[i][j]=binaryToBase10(temp);
// more code here but it isn't important....