www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - error

reply Concealment <tthuynh1234 gmail.com> writes:
void main(string[] args)
{
     srand(time(null));
     int p1 = rand() % 7;
     p1++;



i compiled this program i wrote... but it keeps giving me an error

main.d(17): Error: undefined identifier 'time'

can someone help me please?
Nov 01 2016
parent reply Adam D. Ruppe <destructionator gmail.com> writes:
On Wednesday, 2 November 2016 at 01:27:32 UTC, Concealment wrote:
 can someone help me please?
did you import anything? `import core.stdc.stdlib;` I think will fix that one, but generally you need an import to use lib functions.
Nov 01 2016
parent reply Concealment <tthuynh1234 gmail.com> writes:
On Wednesday, 2 November 2016 at 01:32:27 UTC, Adam D. Ruppe 
wrote:
 On Wednesday, 2 November 2016 at 01:27:32 UTC, Concealment 
 wrote:
 can someone help me please?
did you import anything? `import core.stdc.stdlib;` I think will fix that one, but generally you need an import to use lib functions.
yea i did import core.stdc.stdlib; but it still gives me the same error
Nov 01 2016
parent Jonathan M Davis via Digitalmars-d-learn writes:
On Wednesday, November 02, 2016 01:36:23 Concealment via Digitalmars-d-learn 
wrote:
 On Wednesday, 2 November 2016 at 01:32:27 UTC, Adam D. Ruppe

 wrote:
 On Wednesday, 2 November 2016 at 01:27:32 UTC, Concealment

 wrote:
 can someone help me please?
did you import anything? `import core.stdc.stdlib;` I think will fix that one, but generally you need an import to use lib functions.
yea i did import core.stdc.stdlib; but it still gives me the same error
It's in core.stdc.time. The druntime modules are supposed to correspond to the C header files, and time is in time.h, not stdlib.h. - Jonathan M Davis
Nov 01 2016