vendredi 27 novembre 2015

Random ints in array C

I'm trying to create an array of random ints, but I get a segmentation fault error. I'm using rand() function, but if I replace the rand() with any number it works.

int *arreglo, cant_int = 1000; //cant_int can be any number.
srand(time(NULL); //also tried with srand(0)
arreglo = (int *) malloc(sizeof(int) * cant_int);

for (i = 0; i < cant_int; i++) {
        arreglo[i] = rand(); // arreglo[i] = 1111 or any number doesn't show error
};




Aucun commentaire:

Enregistrer un commentaire