Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- void new_matrix(int **matrix, int linhas, int colunas){
- // aloca memoria para as linhas
- if ( (matrix = (int**)malloc(linhas * sizeof(int*))) == NULL ) {
- printf("erro de alocação 01\n");
- }
- printf("matrix alocado em %d\n", (int)matrix);
- for (int i = 0; i < linhas; i++) {
- if ( (matrix[i] = (int*)malloc(colunas * sizeof(int))) == NULL){
- printf("erro de alocação 02 \n");
- ; break;
- }else{
- for (int j = 0; j < colunas; j++){
- matrix[i][j] = 0;
- }
- }
- }
- }
- int **matrix_global = NULL;
- main(){
- new_matrix (matrix_global, 10, 10);
- printf("matrix alocado em %d\n", (int)matrix_global);
- //show_matrix(matrix_global, 10, 10);
- }
Add Comment
Please, Sign In to add comment