Search code examples
cpointerscalloc

Save a matrix line into a pointer C


I have this matrix, named Q:

0 0 0 1 0 1 1 1 0 1 1 1 0

0 0 0 0 0 0 0 0 0 0 0 0 0

0 1 0 1 0 1 1 0 0 1 1 1 1

0 0 0 0 0 0 0 0 0 0 0 0 0

0 1 0 1 0 1 0 0 1 1 0 0 0

0 0 0 1 1 0 0 1 1 1 0 1 0

0 0 0 1 1 0 0 1 0 1 0 1 1

0 0 1 1 0 0 1 0 0 1 1 0 1

0 0 1 0 1 1 0 0 0 0 0 0 0

1 0 0 0 1 1 1 1 1 0 1 0 1

0 0 0 0 0 0 0 0 0 0 0 0 0

0 1 0 1 0 1 1 1 0 1 0 0 1

1 1 1 1 1 1 1 0 0 0 1 1 0

and a pointer p dinamically allocated.

p=(int *) calloc(13, sizeof(int));

How can I copy an entire line into p? like this: p <- Q[6][]


Solution

  • use memcpy() like memcpy(p,Q[6],13*sizeof(int));