Store a Matrix

Run Settings
LanguageC
Language Version
Run Command
#include <stdio.h> #define string_length 20 void process(int ***array,int row_count) { int i,j; for(i=0;i<row_count;i++) { for(j=0;j<row_count;j++) { printf("%s ",array[i][j]); } printf("\n"); } free(array); array = NULL; } int main(void) { int row_count; int i,j; scanf("%d",&row_count); int ***array = (int ***) malloc(row_count* sizeof(int*)); for (i=0; i<row_count; i++) { array[i] = (int **)malloc(row_count * sizeof(int)); } for(i=0;i<row_count;i++) { for(j=0;j<row_count;j++) { array[i][j]=(int *)malloc(string_length*sizeof(char)); } } if (array == NULL) { printf("\nMemory allocation issue"); } else { scanf("%c"); //do not delete this it will consume the enter key for(i=0;i<row_count;i++) { for(j=0;j<row_count;j++) { scanf("%s",array[i][j]); } } process(array,row_count); } return 0; }
Editor Settings
Theme
Key bindings
Full width
Lines