|
SteveBob wrote:
just using the rand() function keeps returning 41. Isn't that strange?
It will always return the same sequence of numbers because rand() is a psuedo-random number generator. The way you can get around this problem is by seeding the number generator the first time you use it with a value that always changes, like the current time.
Try something like this:
srand(time());
Build a man a fire, and he will be warm for a day Light a man on fire, and he will be warm for the rest of his life!
|
|
|
|
|
|
Thanks! That fixed the problem!
-- Steve
|
|
|
|
|
|
If I want to get 1, 2 and 3 with EXACT 1/3 chance, how can I do it?
int choice;
srand(time(NULL));
while(1)
{
choice= rand() MOD 3;
.....
}
is there any better method?
Thanks
Sean
|
|
|
|
|
i've taken so much from the forum and i just finished a module: it's time for me to do one good deed =)
call srand, then rand. Quote MSDN:
/* RAND.C: This program seeds the random-number generator
* with the time, then displays 10 random integers.
*/
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
void main( void )
{
int i;
/* Seed the random-number generator with current time so that
* the numbers will be different every time we run.
*/
srand( (unsigned)time( NULL ) );
/* Display 10 numbers. */
for( i = 0; i < 10;i++ )
printf( " %6d\n", rand() );
}
norm
|
|
|
|
|
Hi all. I'm a new C++ programmer. Wonder if anyone know how to draw a tree graph with C++? without calling packaged libraries.
|
|
|
|
|
amica wrote:
without calling packaged libraries.
This means you want to write all the code yourself (not that I know what you intend with a packaged library). Since you already told us you don't know how, do you expect us to write the code for you, or do I misunderstand your definition of packaged?
|
|
|
|
|
Well, I wanted some ideas to do it myself. Calling plotting routines in any visual tools doesn't give me the experience of how to put the tree out on the paper. I actually intend to put the tree result out in SVG.
|
|
|
|
|
tree is simple in concept and complex in implementation... it's just a bunch of nodes and links. There'll be a lot of recursion and depending on what feature u wish to support... the most basic config is to create a bunch of nodes, each "pointing" to each other.
i built one sometime ago. lost it now and the reason i built it is that i couldnt find one for free that's ANSI compliant - i needed something for unix box as well as for Windows.
anyway, u do know how to build a link list do u? you tree class prolly look like this:
class CNode
{
private:
CNode();
void * pNext; //point to "next" node
void * pPrev; //point to "prev" node
void * pParent; //point to yr daddy
void * pFirstChild; //point to amica junior
...
..
public:
int AddChild();
int RemoveChild(int nIndex);
int SetParent();
int SetPrev(); //Just remember when u attach a Node, u're forming a relationship BETWEEN TWO nodes. so, the pNext and pPrev will need to be changed for BOTH NODES involved.
int SetNext();
...
...
};
class CTree
{
private:
void * pRootNode;
public:
... whatever u'd like to implement to help yr client to access the nodes...
GetRoot();
GetNode(int nLevelID, int nItem);
};
Good luck. It's my second good deed today, time for bed before sunrise =)
norm
|
|
|
|
|
A newsteler I got today about Intel C++ Compiler.Does any of you even used that?
|
|
|
|
|
I have an application to which I need to add a monitor thread for testing things in debug mode.
I need to start the thread when the test is started and it needs check if a message box or dialog is popped up and if so close it.
When the test is complete the thread is shut down again.
What is the simplest way to achieve this? Sample code would be most helpful.
Thanks in advance
Happy programming!!
|
|
|
|
|
What is the best way of upgrading an application via the web? I would prefer it to be included as a dll instead of a stand alone exe. My thought would be to check a dat file for a version change and a url to the upgrade. How would I close the running app to replace it with a newer version? How could I control who had access to download upgrades? Any sudo code would be nice thanks in advance.
All ideas are excepted, thanks.
Darroll
|
|
|
|
|
Imho, there's probably no "best" way to do this, but there certainly are a number of alternatives. You should pick the one that works best for your type of app. Here are a couple off the top of my head. I'm sure other people could come up with smarter ideas.- Load all your DLLs explicitly (using
LoadLibrary() ). This lets you replace DLLs on the fly. Your main app would be the driver for the upgrade task, allowing the user to upgrade without exiting the app. Imho, this is likely to be a lot of work, since you have to design your app from the start to load its behavior from DLLs, and have very little business logic within the app itself.
- Spawn an external upgrader app that only knows how to check for a newer version, shutdown the current version, upgrade the app, and restart the upgraded version. This is relatively easy to do and puts almost no constraints on the design of your app.
/ravi
Let's put "civil" back in "civilization"
http://www.ravib.com
ravib@ravib.com
|
|
|
|
|
This is weird, I've never seen this before and can't track down any documentation on what exactly it means, but a test application that I'm working on always states this in the debugger output window when I close it:
The thread 'Win32 Thread' (0x5f0) has exited with code 2 (0x2).<br />
The thread 'Win32 Thread' (0x65c) has exited with code 2 (0x2).<br />
The thread 'Win32 Thread' (0x3a4) has exited with code 2 (0x2).<br />
The thread 'Win32 Thread' (0x3f0) has exited with code 2 (0x2).<br />
The program '[1260] QBTEST.exe: Native' has exited with code 2 (0x2).
There are no errors reported anywhere in the program or above the lines above in the output window and it's pretty straightforward, instantiates a com component works with it, releases it properly and exits. Something I've done thousands of times before with other applications.
Anyone know what this is?
|
|
|
|
|
Every thread and process sets a DWORD when it terminates, called its exit code. Back in the DOS days, commands like "copy" would set their code to indicate success/failure, which batch files could then test with ERRORLEVEL.
However, there's no hard-and-fast rule about what the exit code means. In fact, a thread's code is ignored most of the time, because it's just not important.
So it's nothing to worry about.
--Mike--
"Adventure. Excitement. A Jedi craves not these things."
-- Silent Bob
1ClickPicGrabber - Grab & organize pictures from your favorite web pages, with 1 click!
My really out-of-date homepage
Sonork-100.19012 Acid_Helm
|
|
|
|
|
Good news! Thank you.
- John
|
|
|
|
|
I want to write characters to a CScrollView window one character at a time, much like CEditView. I've seen the MSDN docs on CDC and text related functions, but they work on entire strings. Given the x/y position and the font, how to display just one character? Thanks
|
|
|
|
|
If all you want to do is display text, why not just use a CEditView?
Software Zen: delete this;
|
|
|
|
|
How do I detect if a child control is inside the clipping area of current device context?
I have a ownerdraw listbox with two transparent buttons as child controls. In my listbox DrawItem() handler I need to manually trigger a child controls update in some case. So I like to test if a child window area is inside the clipping area of my pDC.
thanks for some help!
|
|
|
|
|
You can use this code in order to get the current clipping rgn that has been initialized from ::BeginPaint:
HRGN hRgn = ::CreateRectRgn(0,0,0,0);
::GetRandomRgn(hdc, hRgn, SYSRGN);
Then you will need to create a rgn from your child window and you can do an intersection test to determine if your child needs to be repainted. At that point you can force a repaint of your child window with a call to ::RedrawWindow with the interected region.
I have written two articles that may help you, the first is about device contexts and clipping regions and the other is a general article about regions.
Good Luck
Build a man a fire, and he will be warm for a day Light a man on fire, and he will be warm for the rest of his life!
|
|
|
|
|
thanks, the article helps a lot for my understanding!
I feel good to find a solution for my problem.
|
|
|
|
|
Paul Watt wrote:
Then you will need to create a rgn from your child window and you can do an intersection test to determine if your child needs to be repainted. At that point you can force a repaint of your child window with a call to ::RedrawWindow with the interected region.
after playing with some ideas... I use this code now:
BOOL IsClientVisible(CDC* pParentDC, CWnd* pClientWnd)
{
ASSERT(pParentDC);
ASSERT(pClientWnd);
CRect rectClient;
pClientWnd->GetWindowRect(rectClient);
ScreenToClient(&rectClient);
return pParentDC->RectVisible(rectClient);
}
|
|
|
|
|
I want to create a Modal Dialog and be in control of it's position in the app.
Or even be able to dynamically change it's position.
Is this posible?
George W
Software Developer
www.zsystems.ca
|
|
|
|
|
You can do that in two ways, the easy way is to have your dialog call your app and allow your app to determine if it needs to move your dialog.
The hard way may be a lot of work, but if this solution does not work, let me know and I will explain the other method.
Good Luck
Build a man a fire, and he will be warm for a day Light a man on fire, and he will be warm for the rest of his life!
|
|
|
|