How can I get my program to read a larger array ??

Posted on 16th Feb 2014 by admin

Hi:

I have this program that reads from an array to do calculations. The array are just the numbers '1' and '0' in different orders. My problem is that I get the array to read up to 10 characters but for this program I need to be able to read up to 1000 characters. Is there something in my code that I need to change or what am I doing wrong. My program compiles but when it reads it it gets the following error:
Code: terminate called after throwing an instance of 'std::bad_alloc' what(): St9bad_alloc Abort (core dumped)

Any ideas ?? Thanks for the help

Rookie

Here is the code

Code: #include #include // for log using namespace std; double complexity(const double* S, double T) { double c = 1.0; int l = 1; do { int kmax =1; for (int i=0;i= T-1) return (++c); } if (k >= kmax) kmax = k+1; } ++c; l += kmax; } while (l < T); return c; } int main(void) { double T = 12.0; // length of string double* S = new double[100110101110]; double sumc = complexity(S,T); cout << "sumc = " << sumc << endl; double cnorm; cnorm = sumc*log((double)T)/(log(2.0)*((double)T)); cout << "cnorm = " << cnorm << endl; delete[] S; return 0; }

Other forums