Logo Pastebin.fr
Pastebin

Retrouvez, créez et partagez vos snippets en temps réel.

gestion mémoire

typedef struct matrix {
    int nbLig;
    int nbCol;
	double * values;
} matrix_t;

typedef enum{ TXT , BIN } file_mode_t;


matrix_t * consMatrix ( int nlig, int ncol );
matrix_t * cpyMatrix( matrix_t * M );

void freeMatrix( matrix_t ** ptrM );
void printMatrix( matrix_t * M, char * entete );

matrix_t * readMatrix(char * filename , file_mode_t mode);
void writeMatrix(char * filename , file_mode_t mode , matrix_t * M);

matrix_t * scanMatrix();
matrix_t * addMatrix ( matrix_t *  A, matrix_t *  B );
matrix_t * multMatrix ( matrix_t *  A, matrix_t *  B );















#include "../include/matrix.h"
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>


matrix_t * consMatrix ( int nlig, int ncol ) {
    matrix_t *  result = malloc(sizeof(*result));

    result->nbCol = ncol;
    result->nbLig = nlig;
    result->values = calloc(nlig*ncol, sizeof(double));

    return result;
}

matrix_t * cpyMatrix( matrix_t * M ){
    matrix_t *  copy = consMatrix(M->nbLig, M->nbCol);
    for (int i=0; i<(M->nbCol)*(M->nbLig); i++) {
        copy->values[i] = M->values[i];
    }

    return copy;
}

Créé il y a 1 semaine.

Rechercher un Pastebin

Aucun paste trouvé.