mercredi 18 octobre 2017

how to use loop on a matrix only with pointers (no index at all) in c [duplicate]

This question already has an answer here:

i want to use loop on a matrix from a function, meaning i need to send pointer as a parameter. i couldnt figure it out really. every element in matrix is equal to a random binary digit.

#include <stdio.h>

#define HEIGHT 4
#define WIDTH 5

void initialize(int *pboard)
{
    int i, j;
    srand(time(NULL));
    for (i = 0; i < HEIGHT; i++)
        for (j = 0; j < WIDTH; j++)
            *(pboard + sizeof(int))+ sizeof(int)) = rand() & 1;
}

int main()
{
    int i,j;
    int board[HEIGHT+1][WIDTH+1];
    int *pboard;
    initialize(*pboard);
}




Aucun commentaire:

Enregistrer un commentaire