1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
|
#include <stdlib.h>
#include <stdio.h>
int citire(int ***a,int *m,int *n)
{
int i,j;
printf("m=");scanf("%d",m);
printf("n="); scanf("%d",n);
*a=(int**)malloc((*m)*sizeof(int *));
if (*a == NULL){
printf("ERROR: out of memory\n");
return 1;
}
for(i=0;i<*m;i++){
(*a)[i]=(int*)malloc((*n)*sizeof(int));
if ((*a)[i] == NULL){
printf("ERROR: out of memory\n");
return 1;
}
}
for(i=0;i<*m;i++)
for(j=0;j<*n;j++) {
printf("[%d][%d]=",i,j);
scanf("%d",&(*a)[i][j]);
}
}
int main() {
int **a,m,n;
int i,j;
if (citire(&a, &m, &n) == 0){
for (i=0;i<m;i++){
for (j=0;j<n;j++)printf("%d",a[i][j]);
printf("\n");
}
} else {
printf("\n ERROR IN ARRAY ALLOCATION!");
}
return 0;
}
|