I'm attempting to write a program in which a helper function returns a random integer between -999 and 999 and returns it for use in the main function.
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int rand(void) {
int n;
n = ((rand() % 1998 + 1) - 999);
return n;
}
int main() {
srand(time(NULL)); /* seed the random number generator */
printf("%d\n",rand());
return 0;
}
However, despite many different tweaks and simplifications of the main function to debug at bare bones, I'm still getting a segmentation fault.
What am I missing? What am I doing wrong?
Aucun commentaire:
Enregistrer un commentaire