You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

61 lines
970 B

#include <iostream>
#include <cstdlib>
#include <stdio.h>
using namespace std;
void array_alloc(double **arr, long arrsize)
{
try
{
arr = new double* [arrsize];
arr[0] = new double [arrsize*arrsize];
for(long i = 1; i < arrsize; i++)
arr[i] = arr[i-1] + arrsize;
}
catch (bad_alloc& ex)
{
cerr << "Could not allocate memory for array" << endl;
exit(1);
}
}
void array_destroy(double **arr)
{
delete [] arr[0];
delete [] arr;
}
int main(int argc, char *argv[])
{
double **A=NULL;//, **B=NULL, **C=NULL;
long rozmiar=0;
char *endptr;
if (argc < 3)
{
cerr << "Usage: " << argv[0] << " <n> <size>" << endl;
exit(1);
}
rozmiar = strtol(argv[2], &endptr, 10);
if (*endptr)
{
cerr << "Invalid array size format" << endl;
exit(1);
}
if (rozmiar <= 0)
{
cerr << "The number of matrix dimension must be positive" << endl;
exit(1);
}
array_alloc(A, rozmiar);
getchar();
//jeszcze czyszczenie pamięci
exit(0);
}