• Advertisement

Archived

This topic is now archived and is closed to further replies.

using srand()

This topic is 5934 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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 ;

Share this post


Link to post
Share on other sites
Advertisement
The only things that can be put outside of a function are declarations (including assignments to global variables).

Share this post


Link to post
Share on other sites
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?!?

Share this post


Link to post
Share on other sites
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 !".

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

  • Advertisement