Im trying to read a file with given by user aboslute path. This is how im getting this path:
const char* WavRead::getFilePath(){
std::string input;
std::cout << "Input wave file name: ";
std::cin >> input;
std::cin.get();
filePath = input.c_str();
return filePath;
}
Then im passing it like this:
void WavRead::run(){
const char* temp_filePath;
temp_filePath = WavRead::getFilePath();
WavRead::readFile(temp_filePath);
}
And finally im trying to open a file with given absolute path (ex. D:\daisy.wav)
int WavRead::readFile(const char* filePath){
wav_hdr wavHeader;
int headerSize = sizeof(wav_hdr);
FILE* wavFile = fopen(filePath, "r");
if (wavFile == nullptr){
fprintf(stderr, "Unable to open wave file: %s\n", filePath);
return 1;
}
size_t bytesRead = fread(&wavHeader, 1, headerSize, wavFile);
fprintf(stderr, "Header size: %d\n", bytesRead);
return 0;
}
But this doesn't work. File doesn't load and cosnole shows me this answer:
"Unable to open wave file: !"