|
how to call srand(time(NULL));
When compile, I got:
: error C2064: term does not evaluate to a function
at the line:
srand(time(NULL));
Please help to identify what I missing?
|
|
|
|
|
try this:
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
int main( void )
{
int i;
srand( (unsigned)time( NULL ) );
for( i = 0; i < 10;i++ )
printf( " %6d\n", rand() );
printf("\n");
{
int RANGE_MIN = 0;
int RANGE_MAX = 100;
for (i = 0; i < 10; i++ )
{
int rand100 = (((double) rand() /
(double) RAND_MAX) * RANGE_MAX + RANGE_MIN);
printf( " %6d\n", rand100);
}
}
}
|
|
|
|
|
Xing Chen wrote:
int rand100 = (((double) rand() /
(double) RAND_MAX) * RANGE_MAX + RANGE_MIN);
ftfy:
int rand100 = (((double) rand() /
(double) RAND_MAX) * (RANGE_MAX - RANGE_MIN) + RANGE_MIN);
Software rusts. Simon Stephenson, ca 1994.
modified on Thursday, May 6, 2010 3:17 AM
|
|
|
|
|
What exactly does casting the return value of time() to unsigned do to address the C2064 error?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
I put you suggested. I got the same problem in my program.
I tested in a small program, it OK. Someconflict with my program.
Thanks
|
|
|
|
|
Hello everybody !
I want to transformation some numbers.
just like:
char szTemp[5] = "300";
1、How to convert szTemp to 8# value (300).
2、And then ,how to convert 8# 300 to 16# C0 ?
|
|
|
|
|
|
What does 8# and 16# represent? The radix, perhaps.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
hi,
i am doing vc++ course, i want to store the image in to an byte array that comes from web cam, after storing that data i want to display in to the server from byte stream. can any one help
thanks
|
|
|
|
|
Sure,
You get a byte stream from a webCam, & you'd like to display said image. Correct?
Well, I'll assume that your data is pointed to by *rawData and that the lines aren't padded (each horizontal line of the image consumes width*3 bytes)
wouldn't you just start-out by writing a few functions that will allow you to get all of the pixels one-by-one and insert them into a HBITMAP object?
As a start, how about something to get pixel values (watch for endianess)
COLORREF getPixelFromRawData(int x, int y)
{
char *data, r, g, b;
long index;
data = rawData;
index = (y*widthPixels*3) + (x*3)
r = data[index+0];
g = data[index+1];
b = data[index+2];
return RGB(r,g,b)
}
|
|
|
|
|
Hi,
I am reading a text file into my richedit ctrl via Streamin call back function
When I finish processing the files the Text is displayed in the RichEdit as if I had entered "SELECT ALL" from an Edit menu selection ...
thsnk
|
|
|
|
|
I would say yes to your statement, when you finished reading, the whole text is selected.
I suspect that your question is, how to unselect the text. Therefor call SetSel( 0, 0); member function of your CRichEditCtrl derived control after finishing reading.
|
|
|
|
|
That's it thankx also puts to the top of the text
|
|
|
|
|
Hey
Can anyone tell me, whats the difference between if any, of using a bool and a BOOL?
|
|
|
|
|
bool uses 1 byte. It is a data type built into the compiler.
BOOL uses 4 bytes. it is a type definition of an int in the file windef.h .
|
|
|
|
|
BOOL was a workaround used before compilers supported bool (or for use in C, which doesn't support bool ). BOOL isn't actually a distinct type but a synonym for int :
typedef int BOOL;
Similarly, the constants TRUE and FALSE are just #defines for the numbers 1 and 0.
On the other hand bool is a type.
Steve
|
|
|
|
|
1、BOOL is Microsoft's macro . In fact, is only 4 bytes of int type. This definitions ,you can find it in the VC setup directory (WINDEF.h、AFX.H), It can be found this following code:
typedef unsigned long DWORD;
typedef int BOOL;
typedef unsigned char BYTE;
typedef unsigned short WORD;
typedef float FLOAT;
#define FALSE 0
#define TRUE 1
#define NULL 0
bool is C/C + + keywords, about MSDN2005 help document, explained below:
This keyword is a built-in type. A variable of this type can have values true and false. Conditional expressions have the type bool and so have values of type bool. For example, i!=0 now has true or false depending on the value of i.
The values true and false have the following relationship:
When a postfix or prefix ++ operator is applied to a variable of type bool, the variable is set to true. The postfix or prefix -- operator cannot be applied to a variable of this type.
The bool type participates in integral promotions. An r-value of type bool can be converted to an r-value of type int, with false becoming zero and true becoming one. As a distinct type, bool participates in overload resolution.
2、Define BOOL and bool of the reasons.
In the memory space,the true、false、null is occupying 1 bytes.But TRUE、FALSE、NULL is occupying 4 bytes.
According to the Intel CPU's paging memory mechanism, 4 bytes can prevent memory inattentive,
it can prevent to produce more ram pieces,and help the data transmission.
|
|
|
|
|
Hi Guru,
Please correct me. I am trying to delcare, define, and call a two dimensional array like:
declare in the header file:
void CCvib_procDlg::time(float*);
Define:
void CCvib_procDlg::time(float delms[][6])
{ ... code ... }
call:
time(&delms[0][0]);
When I tried to compile, I got:
error C2511: 'time' : overloaded member function 'void (float [][6])' not found in 'CC_vib_procDlg'
Please correct mm. Thanks
modified on Wednesday, May 5, 2010 4:39 PM
|
|
|
|
|
The signature for the declaration and definition must be the same.
Use void time(float delms[][6]); in the header file.
|
|
|
|
|
Thanks,I changed the code to what you suggest:
declare:
void class:time(float delms[][6]);
define:
void class:time(float delms[][6]) { ...};
but the call:
time(delms)
not compile, giving error:
error C2664: 'time' : cannot convert parameter 1 from 'float ** ' to 'float [][6]'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
Please correct
Thanks
|
|
|
|
|
|
Thanks.
This is how delms declared:
float**delms;
delms = new float*[1000];
for (int i=0;i<1000;i++)
{
delms[i]=new float[6];
for (int j = 0; j < 6; j++)
delms[i][j] = 0.0;
}
|
|
|
|
|
In this case make the declaration and definitions as -
void time(float* delms[6]);
|
|
|
|
|
Thanks. It compiles.
Since the square brackets have a higher precedence than the de-referencing operator, this declares an array of 6 pointers to the type float
Any comments please?
Thanks
modified on Wednesday, May 5, 2010 7:12 PM
|
|
|
|
|
I would suggest you spend some time practicing reading declarations using the right-left rule[^]. It's invaluable to really understand what's going on.
The wonderful thing about the Darwin Awards is that everyone wins, especially the members of the audience.
|
|
|
|