This week only. Pastebin PRO Accounts Christmas Special! Don't miss out!Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Feb 3rd, 2013  |  syntax: C  |  size: 0.92 KB  |  views: 33  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. void create_matrix(int nbColumns, int nbRow, char **matrix)
  5. {
  6. int i,j;
  7.  
  8.     matrix = calloc( nbColumns, sizeof(char*));
  9.  
  10.     if( matrix == NULL ){
  11.  
  12.         printf("Impossible to allocate");
  13.         exit(EXIT_FAILURE);
  14.  
  15.     }
  16.  
  17.     for( i = 0 ; i < nbRow ; i++ ){
  18.  
  19.         matrix[i] = calloc (nbColumns, sizeof(char*));
  20.  
  21.         if( matrix[i] == NULL ){
  22.  
  23.           printf("Impossible to allocate");
  24.           exit(EXIT_FAILURE);
  25.  
  26.         }
  27.     }
  28.  
  29.  
  30.     /* Test filling*/
  31.     for(i = 0; i < nbRow; i++){
  32.  
  33.         for(j = 0; j < nbColumns; j++){
  34.             matrix[i][j] = 'I';
  35.         }
  36.  
  37.     }
  38.  
  39.         //return matrix;
  40. }
  41.  
  42.  
  43. int main(){
  44.     int i,j;
  45.  
  46.     char **matrix;
  47.  
  48.     create_matrix(8,6,matrix);
  49.  
  50.     //matrix = create_matrix(8,6);
  51.  
  52. for(i = 0; i < 6; i++){
  53.     for(j = 0; j < 8; j++){
  54.         printf("%c ",matrix[i][j]);
  55.     }
  56.     printf("\n");
  57. }
  58.  
  59. }
clone this paste RAW Paste Data