0

我有一个奇怪的问题。我有一个需要返回到另一个函数的数组。问题是它必须被输出/转换为

(unsigned)(unsigned char)

处理数据的函数是 char* 类型。这是我在其中转换数据的函数:

char* Wav::readHeader(ifstream &file)
{
file.read(this->chunkId,                                 4);
file.read(reinterpret_cast<char*>(&this->chunkSize),     4);
file.read(this->format,                                  4);

file.read(this->formatId,                                4);
file.read(reinterpret_cast<char*>(&this->formatSize),    4);
file.read(reinterpret_cast<char*>(&this->format2),       2);
file.read(reinterpret_cast<char*>(&this->numChannels),   2);
file.read(reinterpret_cast<char*>(&this->sampleRate),    4);
file.read(reinterpret_cast<char*>(&this->byteRate),      4);
file.read(reinterpret_cast<char*>(&this->align),         2);
file.read(reinterpret_cast<char*>(&this->bitsPerSample), 4);

char testing[4] = {0};
int testingSize = 0;

while(file.read(testing, 4) && (testing[0] != 'd' ||
                                testing[1] != 'a' ||
                                testing[2] != 't' ||
                                testing[3] != 'a'))
{

    file.read(reinterpret_cast<char*>(&testingSize), 4);
    file.seekg(testingSize, std::ios_base::cur);

}

this->dataId[0] = testing[0];
this->dataId[1] = testing[1];
this->dataId[2] = testing[2];
this->dataId[3] = testing[3];



file.read(reinterpret_cast<char*>(&this->dataSize),     4);

this->data = new char[this->dataSize];

file.read(data,                           this->dataSize);

for(unsigned i=0; (i < 20); i++)
{
    //cout << (unsigned)(unsigned char)data[i] << endl; 

}

return (unsigned)(unsigned char) data;
}

在另一个函数中,我有这个:

unsigned char* data = this->readHeader(file);

谁能看到我哪里出错了?

谢谢 :)

4

1 回答 1

1
this->data = new char[this->dataSize];

所以,大概,this->data有 type char*。很好:这也是函数的返回类型。所以return data似乎是正确的代码。

于 2012-09-09T11:22:00.110 回答