我是C ++的新手,但希望我能正确地询问这个问题。
如果存在一个** ptr,存储多个指向C样式字符串的指针,那么如何将** ptr的第N个元素分配给一个变量?
const char** audioArrays[]{ turretDetectionWavFiles, turretActivationWavFiles, turretSearchingWavFiles, turretPowerDownWavFiles, turretAttackWavFiles, turretMovedWavFiles,
turretDie };
** ptr的第0个元素是turretDetectionWavFiles []
const char* turretDetectionWavFiles[]{ "turret_active_1.wav", "turret_active_2.wav", "turret_active_3.wav", "turret_active_4.wav", "turret_active_5.wav",
"turret_active_6.wav", "turret_active_7.wav", "turret_active_8.wav" };
在这里,我总是收到“ turret_activate_1.wav”
void AudioClass::playAudio(char* incomingData, int MAX_DATA_LENGTH, const char** audioArrays,
const int sizeOfAudioArrays)
const char* audioArraysChars{};
int audioArraysIndex{};
int strcmpResult{};
if ((strcmpResult = strcmp(incomingData, "turretDetectionWavFiles") == 0)) //turretDetectionWavFiles
{
audioArraysChars = audioArrays[0];
audioArraysIndex = 0;
}
因此,除了分配“ turret_active_1.wav”之外,我还需要分配不是turretDetectionWavFiles数组(audioArrays [0])的一个元素(例如,第3个元素),而是turretActivationWavFiles(audioArrays [1])数组。