|
Thank you very much,Tim!
free like a bird
|
|
|
|
|
Hello,
I'm just wondering why your message subject is: "To Michael Dunn"?
Multiply it by infinity and take it beyond eternity and you'll still have no idea about what I'm talking about.
|
|
|
|
|
It may be more appropriate to be "Dear Mr. Dunn"!
Ant.
I'm hard, yet soft. I'm coloured, yet clear. I'm fruity and sweet. I'm jelly, what am I? Muse on it further, I shall return! - David Williams (Little Britain)
|
|
|
|
|
Recently, I write a program.And I write a WinMain function for it. But I don't know where and how to initialize the parameters of the function. Should I to initialize them by myself? Or the system will intialize them?
Where can I find the initializtion of the parameters
hInstC,hInstP,lpCmdLine,nCmdShow?
the function is as follows:
int PASCAL WinMain(HINSTANCE hInstC, HINSTANCE hInstP, LPTSTR lpCmdLine, int nCmdShow)
{..................}
free like a Bird
|
|
|
|
|
|
Hello All,
I am new to C++ and am trying to do some DSP programming. I would like to write the following function
y(n) = (1-a)*x(n-1) + a*y(n-1)
The arguments to this function are all floats - "x", "y" and "a".
Could somebody help me with this?
|
|
|
|
|
I could help you if you can answer these 2 questions:
(1) is x a function (if so, what is it)?
(2) what's the definition of y(0) ?
/ravi
My new year's resolution: 2048 x 1536
Home | Articles | Freeware | Music
ravib@ravib.com
|
|
|
|
|
Thanks, Ravi.
To answer your questions, this function which I'll call SmoothingFunction, is called by another function by name, SmoothCoeffs().
I have two arrays, Coeff[] and Smooth[], each with 5 elements. Values in the array Coeff[] are "smoothed" and then stored in Smooth[].
Here is the SmoothCoeffs() function:
NUM_ITER is 5.
<br />
inline void cDSP::SmoothCoeffs()<br />
{<br />
float *nStart = &gnCoeff[mnCoeffIndex];<br />
float *nFin = &gnSmooth[mnCoeffIndex];<br />
<br />
for (int i = 0; i < NUM_ITER; i++)<br />
{<br />
SmoothingFunction(nStart, nFin, mnSmoothCoeff);<br />
}<br />
<br />
mnCoeffIndex += NUM_ITER;
<br />
if (mnCoeffIndex >= NUM_COEFF)<br />
mnCoeffIndex = 0;
}<br />
"x" represents an element of Coeff() and "y" represents an element of Smooth().
Hope that helps!
|
|
|
|
|
OK, so that implies x and y are simply floating point values and not functions. But then I'm confused by your original definition, viz:
y(n) = (1-a)*x(n-1) + a*y(n-1)
To me, that says y is a function of n , whose definition includes the value y(n-1) . This is pretty easy to code recursively, but then I need to know the exit condition (eg: y(0) is arbitrarily defined as some value). Assuming y(0) is zero, I think the function you want is:
#define EPSILON 0.0000001
double y
(float n,
float a,
float x)
{
if (fabs (n) < EPSILON)
return (0.0);
return ((1.0 - a)*x*(n - 1.0) + (a*y(n-1)));
} /ravi
My new year's resolution: 2048 x 1536
Home | Articles | Freeware | Music
ravib@ravib.com
|
|
|
|
|
Hi Ravi,
I should've probably defined it as follows:
y[n] = (1-a)*x[n-1] + a*y[n-1]
y[n] and x[n] are the elements of two arrays, Smooth[] and Coeff[] respectively.
|
|
|
|
|
OK, it looks like you've answered your own question, then?
/ravi
My new year's resolution: 2048 x 1536
Home | Articles | Freeware | Music
ravib@ravib.com
|
|
|
|
|
Hello, Could somebody please post a very simple function which takes a file path as a function, and recursively lists all files and folders found under that path?
I've found a few other examples on the 'net, but they seem to be focused at older C compilers, and just won't compile under Visual Studio.
If somebody could please help out with this, I'd greatly appreciate it!!!
Thanks in advance,
--Jon
|
|
|
|
|
|
Well, sort of... I've seen that before, but I'm a newbie to C++, though very familiar with c-styled Perl, and could not boil down a simple recursive function from that to be used in a console app... Still so many things in that demo app that are so foreign to me, that I have a really hard time making heads and tales of it.
|
|
|
|
|
here's an example using the CFileFind class.
void MyClass::GetFiles(CString strPath,BOOL bRecurse)
{
CFileFind finder;
CString strFile;
BOOL bWorking = finder.FindFile(strPath + _T("\\*.*"));
while(bWorking)
{
bWorking = finder.FindNextFile();
if(finder.IsDirectory() && !finder.IsDots() && bRecurse)
{
strFile = finder.GetFilePath();
GetFiles(strFile,bRecurse);
}
if(!finder.IsDirectory && !finder.IsDots())
{
strFile = finder.GetFilePath();
}
}
}
you should be able to use the function like this:
GetFiles("C:\\MyProjects",TRUE);
this should get all the files in that directory and all subdirectories.
to only get the files with one folder, just call with a second parameter of false
[insert witty comment here]
bdiamond
|
|
|
|
|
I have a BYTE array of 4 and I want to convert it to a decimal..how is this done.
Example:
<br />
BYTE SomeHex[4];<br />
<br />
SomeHex[0] = 0x00;<br />
SomeHex[1] = 0x00;<br />
SomeHex[2] = 0x27;<br />
SomeHex[3] = 0x30;<br />
So how do I convert this array to a decimal of 10032?
Thanks
Tom Wright
tawright915@yahoo.com
|
|
|
|
|
Just FYI, if you're on an x86 machine, then the bytes are backwards.
You don't convert from hex to decimal, you just put the number in an int variable and use it. How you output the value (hex, octal, binary, etc.) isn't related to how the value is stored.
--Mike--
Personal stuff:: Ericahist | Homepage
Shareware stuff:: 1ClickPicGrabber | RightClick-Encrypt
CP stuff:: CP SearchBar v2.0.2 | C++ Forum FAQ
----
Pinky, are you pondering what I'm pondering?
I think so Brain, but if we shaved our heads, we'd look like weasels!
|
|
|
|
|
So...and correct me if i'm wrong.....if I move Somehex to an int...like:
int intVal = SomeHex;
then the value in intVal will be 10032? I've tried this but I get a compiler error saying "cannot convert from BYTE[4] to int". And if I type cast it as an int then I get 0x0012f408 as a value, which is not right.
So can you explain more please?
Tom Wright
tawright915@yahoo.com
|
|
|
|
|
How about
int i1 = (int)SomeHex[0];<br />
int i2 = (int)SomeHex[1];<br />
int i3 = (int)SomeHex[2];<br />
int i4 = (int)SomeHex[3];
or maybe try this:
int* intVal = (int*)SomeHex;<br />
int intVal2 = *intVal;
Haven't tested either one, so BEWARE. But hopefully one of these will work or get you on the right path.
[insert witty comment here]
bdiamond
|
|
|
|
|
Nope.....just returning a hex value of 0x30270000, which is not right.
Thanks
Tom Wright
tawright915@yahoo.com
|
|
|
|
|
To store the bytes into an int , I would do:
BYTE by[4] = { 0x30, 0x27, 0, 0 };
int n;
n = *(int*) &by[0]; Keep in mind that the order of the bytes is CPU-specific. On x86 it's low->high as I showed above.
Tom Wright wrote:
And if I type cast it as an int then I get 0x0012f408 as a value, which is not right.
That's because a cast isn't a magical command that makes the compiler read your mind. You need to understand exactly what a cast does, and avoid just "throwing in casts" hoping to make it work. (This isn't a flame, it's a difficult subject, I know.)
Casting by to int returns the value of &by[0] , which in your case was 0x0012f408
--Mike--
Personal stuff:: Ericahist | Homepage
Shareware stuff:: 1ClickPicGrabber | RightClick-Encrypt
CP stuff:: CP SearchBar v2.0.2 | C++ Forum FAQ
----
If my rhyme was a drug, I'd sell it by the gram.
|
|
|
|
|
Michael Dunn wrote:
Keep in mind that the order of the bytes is CPU-specific. On x86 it's low->high as I showed above.
I see what you are saying. Here is the value that I see when I view it thru quick watch: 0x30270000 Which is reversed from what is in the array.
Okay so if I reverse this then I'll get the right Hex value in my int.
Questions:
1. The value I see in quick watch...is this the hex value or the int value?
2. If it's the hex value then I still need to convert this to a usable int. What I mean is that this BYTE array is part of a data stream from a socket.
<br />
struct ParseData{<br />
BYTE STAP[4]; <br />
BYTE BlockLen[4];<br />
BYTE HDRLen[2];<br />
BYTE FunctionCode[2];<br />
BYTE ValField[4];<br />
BYTE DataLen[4];<br />
BYTE MsgStatus[2];<br />
BYTE Dest[2];<br />
};<br />
ParseData myStuff;<br />
memcpy(&myStuff, dataBuffer, sizeof(myStuff));<br />
char* DataPacket = new char[myStuff.DataLen];<br />
It tells me the length of another array in the stream which is a datapacket. So this BYTE array is the packet lenght. I've set up the data packet as a char* Datapacket; Can I initialize it like this:
char* DataPacket = new char[n]; ??? and will this be the size of 10032 or 2730?
Really I'm trying to understand this and I really appreciate your help
Thanks
Tom Wright
tawright915@yahoo.com
|
|
|
|
|
I got it..here is my code:
<br />
BYTE NewDataLen[4];<br />
NewDataLen[0] = myStuff.DataLen[3];<br />
NewDataLen[1] = myStuff.DataLen[2];<br />
NewDataLen[2] = myStuff.DataLen[1];<br />
NewDataLen[3] = myStuff.DataLen[0];<br />
<br />
int nDataLength;<br />
nDataLength = *(int*) &NewDataLen[0];<br />
CString someString;<br />
someString.Format("Here is the value: %d", nDataLength);<br />
AfxMessageBox(someString);<br />
I'm sure there is an easier way to do the reverse but my model is "simplicity is best"...ah I'll tweak this as I go.
Now that I have my DataLen I can size my char array and put in my data.....
Thanks for the help again.
Tom Wright
tawright915@yahoo.com
|
|
|
|
|
|
You could (and should) just use the <a href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winsock/winsock/ntohl_2.asp">ntohl()</a> function to fix the byte order of 32-bit ints received through sockets.
|
|
|
|