Putting functions in a header file
Ok I am learning how to put functions that i write into a header file and then including that file in my source code. But I keep getting and error for undefined reference to rndNumber(), but the other function I have works fine when I call it. Here is the code to my header file:
Code:
#include <time.h>
int rndNumber(int range)
{
int x,range;
srand((unsigned)time(NULL));
x = rand()%range;
return x;
}
void quit(void)
{
char x;
printf("Press q to quit.....");
lbl1:
while(kbhit() == 0);
if(getch() != 'q')
goto lbl1;
}
And here is the code to my .c file:
Code:
#include <stdio.h>
#include <myfunctions.h>
void quit(void);
int rndNumber(int range);
int main(int argc, char *argv[])
{
int x;
printf("Enter the range:\n");
scanf("%i",&x);
rndNumber(x);
printf("The random number is %i\n",x);
quit();
return 0;
}