using srand()
why do I get this error when I try to get a random nr?
error C2501: ''srand'' : missing storage-class or type specifiers
error C2373: ''srand'' : redefinition; different type modifiers
c:\vc98\include\stdlib.h(308) : see declaration of ''srand''
I use the following code in my program
#include
#include
#include
#include
#include
#include
#include
srand((unsigned)time(NULL)) ;
int block=rand()%7 ;
The only things that can be put outside of a function are declarations (including assignments to global variables).
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
I don''t get it now (the next day) my function alway returns the same number?!?
srand((unsigned)time(NULL)) ;
void RandomPiece()
{
while (!block)
{
block=rand()%7 ;
}
}
what could be wrong?!?
srand((unsigned)time(NULL)) ;
void RandomPiece()
{
while (!block)
{
block=rand()%7 ;
}
}
what could be wrong?!?
Are you sure your while() loop is ever run ?
In debug mode, variables are initialized by VC++ to a pattern of hexadecimal CCCC''s, so that, when you debug your program, if you see CC''s, you can scream "DUH, uninitialized variable !".
In debug mode, variables are initialized by VC++ to a pattern of hexadecimal CCCC''s, so that, when you debug your program, if you see CC''s, you can scream "DUH, uninitialized variable !".
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement