transform matrix 2D to 1D

前端 未结 3 450
温柔的废话
温柔的废话 2021-01-12 20:59

I have an issue passing a matrix 2D to a vector(1D array)with function in C. There is the code of what i want to create:

#include 
#define N          


        
3条回答
  •  萌比男神i
    2021-01-12 21:23

    This is how you do it in 17 times less lines:

    #define N 8
    
    int mat2d[N][N] = { /* stuff */ };
    int vec1d[N * N];
    memcpy(vec1d, mat2d, sizeof vec1d);
    

提交回复
热议问题