I'm using C++ for this.
Right now I have a function that plays a sound
e.g. I call it like this
[code]PlaySound();[/code]
then in the PlaySound function it's something like
[code]LoadWav("../sounds/sound.wav");
PlayWav;[/code]
I want to change it I can do this
[code]PlaySound(filename);[/code]
then in the function
[code]LoadWav(filename);
PlayWav;[/code]
What is the easiest way to do this?
.... Use function parameters?
Is this question super trivial or am I just not understanding it.
Just use a const char* or std::string as a parameter?
[QUOTE=Robbis_1;40236177]Just use a const char* or std::string as a parameter?[/QUOTE]
wow, I feel so stupid
i think this is a case of it's so easy that I couldn't see it, thank you
[QUOTE=o DefcoN o;40236207]i think this is a case of it's so easy that I couldn't see it[/QUOTE]
i dont think so...
I think you're thinking of file names as their own object (opposed to it being a string). Understandable, but now you know.
Pass it from main as argv[] if youre using commandline, then in the function itself do the whole fopen() business. This is what id do for testing purposes in early stages.
[QUOTE=Relaxation;40258720]Pass it from main as argv[] if youre using commandline, then in the function itself do the whole fopen() business. This is what id do for testing purposes in early stages.[/QUOTE]
what the hell
-snip- posted while intoxicated
[QUOTE=Relaxation;40258810]lmao, just saw he said c++, not c!!
but yes, if he wanted to pass a filename from the commandline to the function that opens and plays it, the prototype would look like void playSound(char **file)
and in the main function you would call it like playSound(argv[1]);
e.g. the command line innvocation is ./program soundfile
But thats how i would TEST it in C, due to preferences / tools.
as someone already told the op, filename is just a string.[/QUOTE]
what the fucking hell
[QUOTE=Relaxation;40258810]lmao, just saw he said c++, not c!!
but yes, if he wanted to pass a filename from the commandline to the function that opens and plays it, the prototype would look like void playSound(char **file)
and in the main function you would call it like playSound(argv[1]);
e.g. the command line innvocation is ./program soundfile
But thats how i would TEST it in C, due to preferences / tools.
as someone already told the op, filename is just a string.[/QUOTE]
argv[1] is a char *
also i don't know how to making this a commandline argument has anything to do with what he's talking about
You have to use TCHAR, also use double slashes, not one backslash in C++ when pathing to file.
it will be something like this:
TCHAR fileName[MAX_PATH];
fileName = L"C:\\Users\\Desktop\\music.wav";
LoadWav(TCHAR);
PlayWav(filename);
[QUOTE=cucumber;40570728]You have to use TCHAR, also use double slashes, not one backslash in C++ when pathing to file.
it will be something like this:
TCHAR fileName[MAX_PATH];
fileName = L"C:\\Users\\Desktop\\music.wav";
LoadWav(TCHAR);
PlayWav(filename);[/QUOTE]
TCHAR is non-standard and Windows only. Just use wchar_t if you are required to have Unicode support (which you are not in this example but OP might be depending on his locale and folder names)
[QUOTE=cucumber;40570728]You have to use TCHAR, also use double slashes, not one backslash in C++ when pathing to file.
it will be something like this:
TCHAR fileName[MAX_PATH];
fileName = L"C:\\Users\\Desktop\\music.wav";
LoadWav(TCHAR);
PlayWav(filename);[/QUOTE]
You are trying to LoadWav() a variable type?
Shouldn't it be LoadWav(fileName);
Also don't use TCHAR if you really don't have to.
Sorry, you need to Log In to post a reply to this thread.