|
I'm trying to generate random numbers with
#include <stdio.h>
void main( )
{
int iRandom = 0;
iRandom = ( rand( ) % 100 ) + 1;
printf( "\n\n%d", iRandom );
}
the result is 42 everytime any help please
Microsoft visual c++ 9.0 / Vista
<div class="ForumMod">modified on Monday, June 30, 2008 1:13 AM</div>
|
|
|
|
|
Try to put this line
srand( (unsigned)time( NULL ) );
before calling rand();
-Santosh
« Superman »
|
|
|
|
|
|
you should use srand if you want the sequence to start with a different number each time. Otherwise it always gets seeded to 1, and on your compiler (Visual C++, I'm guessing) the first number generated with a seed of 1 is 41.
The result is displayed as 42 since you always add 1 to the random number.
Somethings seem HARD to do, until we know how to do them.
_AnShUmAn_
|
|
|
|
|
Hi all,
I m using Number property for Edit box,becoz i want to use only digits.
But i also want to enter ".",but it is not accept it please tell me how can i Number property of Edit box where i m also use ".".
Thanks in advance.
IN A DAY, WHEN YOU DON'T COME ACROSS ANY PROBLEMS - YOU CAN BE SURE THAT YOU ARE TRAVELLING IN A WRONG PATH
|
|
|
|
|
"_$h@nky_" wrote: how can i Number property of Edit box where i m also use ".".
You cannot. If you want such a feature, you should handle the WM_CHAR message and filter the unwanted keys..
|
|
|
|
|
Can you please tell me with example.
IN A DAY, WHEN YOU DON'T COME ACROSS ANY PROBLEMS - YOU CAN BE SURE THAT YOU ARE TRAVELLING IN A WRONG PATH
|
|
|
|
|
void CNumericEdit::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
{
char szBuffer[100] = {0};
short int nCounter = 0;
short int iTemp = 0;
int iStartChar = 0;
int iEndChar = 0;
if(nChar == '-')
{
return;
}
if(nChar != VK_BACK && nChar != VK_TAB)
{
if(nChar != '.' && (nChar < '0' || nChar > '9'))
{
return;
}
GetWindowText(szBuffer, sizeof(szBuffer));
if(nChar == '.')
{
GetSel(iStartChar, iEndChar);
if(iStartChar != 0 || iEndChar != static_cast<int>(strlen(szBuffer)))
{
for(nCounter = 0; szBuffer[nCounter] != NULL; nCounter++)
{
if(szBuffer[nCounter] == '.')
{
return;
}
}
}
}
}
CEdit::OnChar(nChar, nRepCnt, nFlags);
}
|
|
|
|
|
this error comes out when i use the above code.
error C2248: 'CWnd::OnChar' : cannot access protected member declared in class 'CWnd'
1> C:\Program Files\Microsoft Visual Studio 8\VC\atlmfc\include\afxwin.h(2631) : see declaration of 'CWnd::OnChar'
1> C:\Program Files\Microsoft Visual Studio 8\VC\atlmfc\include\afxwin.h(1967) : see declaration of 'CWnd'
1>
IN A DAY, WHEN YOU DON'T COME ACROSS ANY PROBLEMS - YOU CAN BE SURE THAT YOU ARE TRAVELLING IN A WRONG PATH
|
|
|
|
|
|
How can i do this?
I m using edit box and other controls on Dialog box,so the base class is CDialog.
IN A DAY, WHEN YOU DON'T COME ACROSS ANY PROBLEMS - YOU CAN BE SURE THAT YOU ARE TRAVELLING IN A WRONG PATH
|
|
|
|
|
Derive a new class from CEdit and override OnChar.
In dialog create a member variable of new Class derived from CEdit.
In DoDataExchange of dialog write
DDX_Control(pDX, <edit control="" id="">, <object of="" derived="" cedit="" class="">);
If you still do not get please see articals which is available in codeproject.
|
|
|
|
|
Thanks.
IN A DAY, WHEN YOU DON'T COME ACROSS ANY PROBLEMS - YOU CAN BE SURE THAT YOU ARE TRAVELLING IN A WRONG PATH
|
|
|
|
|
|
Have you considered a masked edit control?
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Hello everyone,
Am I correct for the understanding of the following three questions about CoInitialize/CoUninitialize?
1.
For each thread which utilizes COM, we need to call CoInitialize/CoUninitialize. Not for each process.
2.
There is no harm to call CoUninitialize even if we do not call CoInitialize? And if we call CoInitialize N times on a thread, we need to call CoUninitialize the same of times (N times, not only 1 time) on a thread to release all resources?
3.
CoInitializeEx will invoke CoInitialize?
thanks in advance,
George
|
|
|
|
|
George_George wrote: For each thread which utilizes COM, we need to call CoInitialize/CoUninitialize. Not for each process.
yes
George_George wrote: And if we call CoInitialize N times on a thread, we need to call CoUninitialize the same of times (N times, not only 1 time) on a thread to release all resources?
yes
George_George wrote: CoInitializeEx will invoke CoInitialize?
No. But CoInitialize calls CoInitializeEx with concurrency model as single-thread apartment.
|
|
|
|
|
Thanks Naveen,
I have tried call CoInitialize multiple times will result in fail? Could you reproduce it?
regards,
George
|
|
|
|
|
Fail means it return E_FAIL ? I hope you have seen the below lines in MSDN
"Typically, the COM library is initialized on a thread only once. Subsequent calls to CoInitialize or CoInitializeEx on the same thread will succeed, as long as they do not attempt to change the concurrency model, but will return S_FALSE"
|
|
|
|
|
Thanks nave,
Question answered. This is what I mean.
regards,
George
|
|
|
|
|
1 and 2 are yes and 3: from th MSDN
New applications should call CoInitializeEx instead of CoInitialize.
|
|
|
|
|
Great reply, thanks Hamid!
regards,
George
|
|
|
|
|
It's said that 32 bit cpu accesses 32 bit data most efficiently.
So does 64 bit.
Is there any type that is always equal to the cpu bit size? (Maybe it should be the data bus size, I'm sure whether they are always equal).
|
|
|
|
|
followait wrote: Is there any type that is always equal to the cpu bit size?
int
modified on Monday, June 30, 2008 12:35 AM
|
|
|
|
|
No, it is 4 bytes in both 32-bit and 64-bit machines.
|
|
|
|