P
Pushker Pradhan
This is similar to my post a few days ago, I'm now doing it correctly but
somehow I get Segmentation errors:
My function gen_matrix allocates memory for x and returns x with some
content:
void gen_matrix(int **x, int numRows, int numCols)
{
long i;
*x = (int *)calloc( (numRows*numCols), sizeof(int) );
for(i = 0; i < numRows*numCols; i++) {
*x = rand();
}
}
Call in main.c:
int *mat = NULL;
int numrows, numcols;
numrows = atoi(argv[1]);
numcols = atoi(argv[2]);
gen_matrix(&mat, numrows, numcols);
This is the error (the memory allocation: calloc fails!):
psp1@leto:~/pdc$ ./main 4 4
Bus Error (core dumped)
Can somebody tell what's wrong?
somehow I get Segmentation errors:
My function gen_matrix allocates memory for x and returns x with some
content:
void gen_matrix(int **x, int numRows, int numCols)
{
long i;
*x = (int *)calloc( (numRows*numCols), sizeof(int) );
for(i = 0; i < numRows*numCols; i++) {
*x = rand();
}
}
Call in main.c:
int *mat = NULL;
int numrows, numcols;
numrows = atoi(argv[1]);
numcols = atoi(argv[2]);
gen_matrix(&mat, numrows, numcols);
This is the error (the memory allocation: calloc fails!):
psp1@leto:~/pdc$ ./main 4 4
Bus Error (core dumped)
Can somebody tell what's wrong?