alokacja pamieci + drobne pierdoly
This commit is contained in:
@@ -1,15 +1,61 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
using namespace std;
|
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[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
|
double **A=NULL;//, **B=NULL, **C=NULL;
|
||||||
|
long rozmiar=0;
|
||||||
|
char *endptr;
|
||||||
|
|
||||||
if (argc < 3)
|
if (argc < 3)
|
||||||
{
|
{
|
||||||
cerr << "Usage: " << argv[0] << " <n> <size>" << endl;
|
cerr << "Usage: " << argv[0] << " <n> <size>" << endl;
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
cout << argv[argc-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);
|
exit(0);
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user