When I try to compile this, it says “testrand.c:(.text+0x11): undefined reference to `rand_number'”
1 #include <stdio.h>
2 #include <time.h>
3
4 int rand_number(int param);
5
6 main()
7 {
8 while(5)
9 {
10 printf("%d", rand_number(15));
11 sleep(1);
12 }
13
14
15 int rand_number(int param)
16 {
17 srand((unsigned int)time(NULL));
18 int x = param;
19 int rn = rand() % x;
20 return rn;
21 }
22 }
But, I’ve clearly defined it up there…
I have tried including time.h in quotation marks, including stdlib.h, etc… but still have no idea what’s going on. Anyone know what’s happening?
This happened because your
rand_numberfunction is defined within other function,main.This should fix your problem: