-1

Hi I've created an array and used malloc to store it so it could use it in a different function but now I'm running into problems with printing the array as it says:

warning: format '%d' expects argument of type 'int', but argument 2 has type 'int *' [-Wformat=]
             printf("1-ere %d -- \n", roll_dice_outcome);

Help please :D

int *roll_multiple_dice(int N){
    int i;
    int *roll_dice_outcome = malloc(sizeof(int) * N);

        for (i = 0; i < N; i++)
        { 
            roll_dice_outcome[i] = (rand() % 6) + 1;
            printf("%d ", roll_dice_outcome[i]);
        }

    return roll_dice_outcome;
}

void play_yatzy(int i, int *roll_dice_outcome){
    
    
        switch (i)
        {
        case 1:
            printf("1-ere %d -- \n", roll_dice_outcome);
            break;
        }
1
  • Your previous question was about returning an array from a function. This is about printing an array. Both questions are very easy to search. Please do some research before posting. SO is not intended as beginner tutoring.
    – klutt
    Commented Nov 17, 2022 at 18:45

1 Answer 1

0

You cant print the array this way.

You need to iterate through all elements and print them individually:

void printResults(const int *results, size_t size)
{
    for(size_t i = 0; i < size; i++)
    {
        printf("Result no %zu = %d\n", size, results[i]);
    }
}
0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.