lundi 4 avril 2016

How should I implement a rollDice() function in C?

I try to implement a function meant to roll a dice a certain amount of time.

#include <stdio.h>
#include <stdlib.h>
#include <time.h>

int * rollDice(int len) //len = times the dice is rolled.
{
    int ints[len];

    int i = len-1;


    while(i>0)
    {

        ints[i--] = (rand()%6)+1;

    }

    return  ints;
}


int main(int argc, const char * argv[])
{


    int * ints = rollDice(10);

    for(int i =0; i<10; i+=1)
    {
        printf("%d ",*(ints+i));
    }
    return 0;
}

Program always prints this, is my conception of pointers false ?

104 0 0 0 1919706998 2036950640 1667723631 1836545636 16 48 




Aucun commentaire:

Enregistrer un commentaire