Advertisement

using srand()

Started by November 20, 2001 01:55 PM
4 comments, last by da_cobra 23 years ago
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
Advertisement
yep you were right
now it works

thanx alot !!!
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?!?
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 !".
"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
ah damn
stupid me
you''re right

when I enter the function block equals to a number so if block!=0 it doesn''t do that while loop

thanx for pointing me that out

This topic is closed to new replies.

Advertisement