#include <stdio.h>
#include <stdlib.h>

struct mat_int{
	int rows;
	int cols; // used size
	int size;
	int* val;
};
void mat_alloc(struct mat_int* p_mat, int row_size, int col_size){
	p_mat->rows = row_size;
	p_mat->cols = col_size;
	p_mat->size = row_size * col_size;
	p_mat->val = (int*)malloc(p_mat->size * sizeof(int));
	return p_mat;
}

void mat_print(const struct mat_int* p_mat){
	for(int p=0; p<p_mat->rows; p++){
		printf("[ ");
		for(int q=0; q<p_mat->cols; q++){
			printf("%d ", p_mat->val[p_mat->cols*p + q]);
		}
		printf("]\n");
	}
}

int main(){
	struct mat_int mat;
	mat_alloc(&mat, 3, 3);
	
	int i=0;
	for(int i=0; i<mat.size; i++){
		mat.val[i] = i;
	}
	
	mat_print(&mat);
	return 0;
}