|
strstr would work, but I only know the string based on a delimiter.
strtok() works so well I was hoping I would have to save off the string first and then put it back in later.
Thanks...guess I'll keep searching....
|
|
|
|
|
substring by using strstr()?
~~~~Code the Dreams~~~~~
|
|
|
|
|
hi
i searched the MSDN but i findout out that the random() function in stdlib.h is not exist.
it seems that it's replaced with srand() and rand() . can anyone explain me how can i use these 2 function or any other to reach random numbers in requested range ? (for example 0 < x < 1000 )
thnx
|
|
|
|
|
|
thanks mr.nishant but it seems that in this example the Range of Figures are not important.
may be i should do something like this :
<br />
int r=1000;<br />
while(1){ r=rand(); if (r<999) break; }
thanks any way.
-=Fight with be Best Die like the Rest=-
|
|
|
|
|
*cough* modulus *cough*
Know that good little % operator?
I wonder what this would do:
min + (rand() % (max - min + 1))
|
|
|
|
|
HellShrimp4free wrote:
but it seems that in this example the Range of Figures are not important.
Correct, in the MSDN example the range isn't important, however you can do the following to limit your range to under 1000:
#include "stdafx.h"
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#using <mscorlib.dll>
#include <tchar.h>
using namespace System;
int _tmain(void)
{
srand( (unsigned)time( NULL ) );
for( int i = 0; i < 10;i++ )
printf( " %6d\n", rand()%1000 );
Console::Read();
}
Nick Parker
You see the Standards change. - Fellow co-worker
|
|
|
|
|
Hi
Those two functions have always been there. In fact I never used (saw ?) the function Random()
Here is how to use them:
// Seed Random-number Generator with Current Time
srand(( unsigned) time(NULL ));
int nRandomData = rand() % 4;
Replace 4 with the Maximum value accepted (1000 in your request)
The call to srand with current time allows the generation of different random sequences. If you start always with the same number, you always got the same sequence ( as far as I remember) ...
HTH
Thierry
|
|
|
|
|
I have a Windows NT service which maintains a pool of objects. The purpose of the pool is to improve performance because the objects being pooled require a signifigant amount of time for construction.
At any given time, there can be from 0-N requests for objects from the pool. There are times when the pool will have no requests at all for days. Other times, it will have 1000s of requests an hour/minute. I keep track of # of requests, avg time between requests, first request, last request, time to allocate, time to fill request, peak objects in pool, peak requests per sec/min, # of requests made when pool was exausted.
I am looking for an algorithm that will limit the number of requests that occur when the pool is exausted while not exceeding a maximum pool size or memory usage. There really is not MAX size, but I don't want to just allocate 1000s all the time. My goal would be to have 75-85% of requests filled by the pool with no waiting.
Currently, the algorithm I use is something like this:
(Pseudocode
long lDesiredPoolSize = lMinSize;
if (lRequestsLast5Minutes > (lRequestsLastHour / 12) && lRequestsLast5Minutes > lDesiredPoolSize)
lDesiredPoolSize = lRequestsLast5Minutes * 1.25;
if (lPoolExaustedRequests > lDesiredPoolSize)
lDesiredPoolSize = lPoolExaustedRequests * 1.25;
if (lRequestsLastHour >= lRequestsAtPeak)
lDesiredPoolSize = lRequestsLastHour * 1.25;
if (lDesiredPoolSize > lMaxPoolSize)
lDesiredPoolSize = lMaxPoolSize;
if (lRequestsLastHour == 0)
lDesiredPoolSize = 0;
I just made this up and tinkered with it, but I wonder if anyone in CPland has any more experience with this kind of thing?
|
|
|
|
|
I get the position of the slider and do a textOut with it. After the slider reaches a 100, and the text says 100, when I slide it back, a part of the last zero doesnt get cleaned off the screen and the textout looks like:
34 ) etc.
How do I make the remnants of the prev numbers go away? I thought of doing an Invalidate() after the textout but then the number totally vanishes (because its not being written out in OnDraw() but in OnHScroll. In HScroll I get the pointer to the scrollbar, so I can GetPos. How would I access this getPos in OnDraw(0 so that I could see the refreshed text?
Appreciate your help,
ns
|
|
|
|
|
Draw a couple spaces after the number? (ie "34 ")
CPUA 0x5041
Sonork 100.11743 Chicken Little
"So it can now be written in stone as a testament to humanities achievments "PJ did Pi at CP"." Colin Davies
Within you lies the power for good - Use it!
|
|
|
|
|
Wow!
I did
s.Format("%d ", position);
and that took care of it!
Thanks!!!
Appreciate your help,
ns
|
|
|
|
|
I've searched all over (CodeProject and the Internet at large) and I have not been able to find the answer to my problem, so here goes.
I have an MDI app where I would like to be able to open a document and immediately present the user with multiple views of the same document -- one will be the primary view, and I'd like to have two secondary views. I know that the CDocument class has a member function called AddView(), but I don't know where to add my secondary views. Where would I add my other views -- in MainFrm, ChildFrm, or elsewhere? And would using the AddView() member function be the appropriate way of accomplishing what I'm trying to do?
Thanks,
Dean
|
|
|
|
|
|
I know how to do a .Create() and make one, but what does one do after retrieving the address the
user enters? WHich control will accept this address and open the webpage it points to? Is there a sample that shows how the addressctrl communicates this info to the ctrl that actually opens the webpage (which also I need to know about)
Thanks
Appreciate your help,
ns
|
|
|
|
|
ARGH - this is killing me. All I am trying to do is take a dialog, bring it to the front, centered, and activated. And I CAN'T for the life of me figure out how to do all three! Here is some code I have tried, in the dialogs, OnInitDialog handler:
BOOL CongratsDlg::OnInitDialog()
{
...
CenterWindow();
ShowWindow(SW_RESTORE);
}
I have tried various parameters in ShowWindow , and I have tried it with the SetWindowPos stuff, and without it... and with it but not ShowWindow... etc.
So what is the magic combination to show and activate a window?
Some background: this is an MFC app. It has no main window - it launches some other app, waits for it to finish, and then pops up this dialog.
Muchas gracias.
Even a broken clock is right twice a day.
|
|
|
|
|
Hmm - I may have answered my own question. It seems like if I have the Start menu active at all - even if I activate it long before this dialog comes up, the window won't activate. It seems that in any other situation, the code I have above works.
Ah well.
Even a broken clock is right twice a day.
|
|
|
|
|
|
Hey guys
I just told someone on a forum that CString has an implicit const char* operator. Now I suddenly realized that this is actually wrong grammar or usage or whatever. I mean implicit operators are the ones the compile does for us huh? Like conversion of int to char etc... So I should not have used the word implicit there, right? But then it's not an explicit operator either cause the user need not actually put a cast there. So can someone gimme some info on best usage practices for such stuff, so that I wont confuse other people in future
Nish
Author of the romantic comedy
Summer Love and Some more Cricket [New Win]
Review by Shog9
Click here for review[NW]
|
|
|
|
|
It is more question of English language, than programming. Stroustrup writes something like "operator const char*() ... provided convenience of an implicit conversion..."(#20.3.7). I understand that as an operator provides some implicit action, but itself cannot be implicit. But again, I am not a native English speaker.
|
|
|
|
|
|
You should have said "an LPCTSTR operator" But seriously, since all operator TYPE() functions can be invoked implicitly, you weren't completely wrong.
--Mike--
If it doesn't move and it should: WD-40. If it moves and it shouldn't: duct tape.
1ClickPicGrabber - Grab & organize pictures from your favorite web pages, with 1 click!
My really out-of-date homepage
Sonork-100.19012 Acid_Helm
|
|
|
|
|
|
Hi.
Anyone know of a portable way
of doing program icons
(the kind you see when looking in a folder)?
Got an example?
How do I go about making
the program icon a separate file
(so if i edit it, i don't have to recompile)?
Any reading you can point me to, i'd really appreciate it.
|
|
|
|
|
So far I'd been making projects with CFormView, so when I wanted to adda handler for the bn_clicked I would just dbl click on the control, say a button, and the ONButtonA type function would be created and automatic messagemap entries made.
Now I have a CView project and am having to add the controls using .Create() so I cant very well dbl click to add the handler automatically. In this case am I responsible for making messagemap entries? Is there no automatic mechanism for this?
Thanks
Appreciate your help,
ns
|
|
|
|