Skip to content
Snippets Groups Projects
Select Git revision
  • 9d338fc1f3b3900a5726620559fa97496aff1edc
  • master default protected
2 results

quadtree.c

Blame
  • matrix.c 958 B
    #include "matrix.h"
    #include <math.h>
    #include <stdio.h>
    #include <stdlib.h>
    
    // typedef struct _matrix {
    //   int m, n;
    //   int **data;
    // } matrix;
    
    //m ligne n col
    error_code matrix_init(matrix *mat, int m, int n) {
    
      mat->data = malloc(m * sizeof(int *));
    
      for (int i = 0; i < m; i++) {
        mat->data[i] = malloc(n * sizeof(int));
      }
    
      mat->n = n;
      mat->m = m;
    
      return ok;
    }
    
    error_code matrix_destroy(matrix *mat) {
    
      for (int i = 0; i < mat->m; i++) {
        free(mat->data[i]);
      }
      free(mat->data);
    
     
      return ok;
    }
    
    error_code matrix_init_from_array(matrix *mat, int m, int n, int data[]){
    
      mat->data= malloc(m * sizeof(int *));
    
      for (int i = 0; i < m; i++) {
        mat->data[i] = malloc(n * sizeof(int));
      
      }
    
     int k=0;
    
      for(int i=0;i<m;i++){
        for (int j = 0; j < n; j++) {
          
          mat->data[i][j]=data[k++];
        }
      }
    
      mat->n = n;
      mat->m = m;
      return ok;
    }
    
    
    
    error_code matrix_clone(matrix *cloned, const matrix mat);