Error concatinating file path and file name....
-
hello guys... I am actually recording a wave file. I have hardcoded the file path but the file name is provided by the user. Now I want to wave file to be stored at this combination of these two which in im successful. Here is what im trying
LPCSTR filePath = "d:\\Audios\\";
LPCSTR fileNamePath = strcat(filePath, strcat(fileName, ".wav")); //NOTE: fileName is the argument to this functionThis is not successful, how can I do that?? thnx
-
hello guys... I am actually recording a wave file. I have hardcoded the file path but the file name is provided by the user. Now I want to wave file to be stored at this combination of these two which in im successful. Here is what im trying
LPCSTR filePath = "d:\\Audios\\";
LPCSTR fileNamePath = strcat(filePath, strcat(fileName, ".wav")); //NOTE: fileName is the argument to this functionThis is not successful, how can I do that?? thnx
overloaded Name wrote:
This is not successful
Please be specific when asking a question. What doesn't work exactly ? In your case, I would guess it is because you are using constant strings (LPCSTR, the C is for constant). Try using LPSTR instead, it should work. Don't forget that strcat will modify the destination string (check the documentation). BTW, it is far more easier to use std::string instead of using raw char pointers.
Cédric Moonen Software developer
Charting control [v3.0] OpenGL game tutorial in C++ -
hello guys... I am actually recording a wave file. I have hardcoded the file path but the file name is provided by the user. Now I want to wave file to be stored at this combination of these two which in im successful. Here is what im trying
LPCSTR filePath = "d:\\Audios\\";
LPCSTR fileNamePath = strcat(filePath, strcat(fileName, ".wav")); //NOTE: fileName is the argument to this functionThis is not successful, how can I do that?? thnx
strcat needs a writeable destination buffer. where is all this text going to be stored? you need a buffer large enough to hold it, I see it nowhere. Here is one way of doing it (C code):
char* result=malloc(1000);
strcpy(result, filePath);
strcat(result, fileName);
strcat(result, ".wav");This is far from optimal, as the size is overestimated, and the string operations are unsafe, they could overrun the destination buffer. It would also fail if filePath doesn't end on a backslash, or fileName already has an extension. But it would work. :)
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
-
hello guys... I am actually recording a wave file. I have hardcoded the file path but the file name is provided by the user. Now I want to wave file to be stored at this combination of these two which in im successful. Here is what im trying
LPCSTR filePath = "d:\\Audios\\";
LPCSTR fileNamePath = strcat(filePath, strcat(fileName, ".wav")); //NOTE: fileName is the argument to this functionThis is not successful, how can I do that?? thnx
-
hello guys... I am actually recording a wave file. I have hardcoded the file path but the file name is provided by the user. Now I want to wave file to be stored at this combination of these two which in im successful. Here is what im trying
LPCSTR filePath = "d:\\Audios\\";
LPCSTR fileNamePath = strcat(filePath, strcat(fileName, ".wav")); //NOTE: fileName is the argument to this functionThis is not successful, how can I do that?? thnx
You could use the PathCombine[^] and PathAddExtension[^] functions, they solve the problems mentioned by Luc Pattyn. e.g.
PathCombine(fileNamePath,filePath,fileName);
PathAddExtension(FileNamePath,".wav");Note the remark, make
fileNamePath
able to hold at least MAX_PATH characters. -
hello guys... I am actually recording a wave file. I have hardcoded the file path but the file name is provided by the user. Now I want to wave file to be stored at this combination of these two which in im successful. Here is what im trying
LPCSTR filePath = "d:\\Audios\\";
LPCSTR fileNamePath = strcat(filePath, strcat(fileName, ".wav")); //NOTE: fileName is the argument to this functionThis is not successful, how can I do that?? thnx
Here is the C++ way to do this -
std::stringstream strm;
strm << filepath << filename << ".wav";std::string str(strm.str());
«_Superman_» _I love work. It gives me something to do between weekends.
-
You could use the PathCombine[^] and PathAddExtension[^] functions, they solve the problems mentioned by Luc Pattyn. e.g.
PathCombine(fileNamePath,filePath,fileName);
PathAddExtension(FileNamePath,".wav");Note the remark, make
fileNamePath
able to hold at least MAX_PATH characters.Pretty handy functions, i did not know they existed. To OP, if you do use them you will need to #include and link with Shlwapi.
[Window Detective] - Windows UI spy utility