-
Beep-Beep
:confused:
Hey does anyone know how to set up this program with a command line that will have: prog sound1 duration1 sound2 duration2....
#include <iostream.h>
#include <stdlib.h>
#include <windows.h>
void soundSequence(int sounds[], int duration [], int numSounds);
int main(int argc, char *argv[])
{
Beep(1000,1000);//1kHz tone for 1 second
Sleep(1000);//Wait for 1 second!!
Beep (2000,1000);//2kHz tone for 1 seconds
Beep (4000,2000);//4kHz tone for 2 seconds
Beep (6000,4000);//6 kHz tone for 4 seconds
system("PAUSE");
return 0;
}
Thanks for your help in advance.
-
-
WARNINGS
The beep() function is platform dependent.
As I recall... With Win98, the frequency and duration will be ignored. You'll get a default beep. With WinXP, the frequency and duration are used only if you don't have a sound card. If you have a sound card, you get the "Windows Default" sound.
-
Code:
#include <iostream.h>
#include <stdlib.h>
#include <windows.h>
void soundSequence(int sounds[], int duration [], int numSounds);
int main(int argc, char *argv[])
{
//Convert the following code into a function with prototype:
//void soundSequence(int sounds[], int duration [], int numSounds);
//main is to read command line arguments and load up arrays to
//pass to function. Allocate memory dynamically for arrays.
//command line: prog sound1 duration1 sound2 duration2.....
//sound of 0 will sleep for the duration.
Beep(1000,1000);//1kHz tone for 1 second
Sleep(1000);//Wait for 1 second!!
Beep (2000,1000);//2kHz tone for 1 seconds
Beep (4000,2000);//4kHz tone for 2 seconds
Beep (6000,4000);//6 kHz tone for 4 seconds
system("PAUSE");
return 0;
}
I hope this is better;)
-
just to point out...
You can't just compare the command line arguments with just the assignment operator
you must use and should I think, use a function like 'strncmp'
ex:
/* check the first argument */
if ( (strncmp(argv[1],"-c",2))==0 )
{
/* do something */
}
else {
printf("Bad command line argument");
}
hope this helps
-
This might help
int main (int argc, char **argv)
{
int numpts = argc - 3;
double *data = new double[numpts];
for (int i = 0; i < numpts; i++)
data[i] = atof (argv[i+3]);
if (strcmp (argc[1], "mav")
{
int winsize = atoi (argv[2]);
}
return 0;
}
Hope this helps some :p