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


Posted on 16th Feb 2014 07:03 pm 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; }

No comments posted yet

Your Answer:

Login to answer
318 Like 27 Dislike
Previous forums Next forums
Other forums

Pulling out some result data from MYSQL
Hey Guys,

I've built a PHP page that has a for just imagine something like registration form

Not showing whole name with mail () script
I sent up a simple mail form with the PHP mail() script. One problem is when it sends an email with

how do I show what a user have selected from a checkbox?
From my code below, how would i show which check boxes have been checked and which radio buttons sel

Calculus Help (and by help I mean homework)
Hrmmm, I hate posting about math homework, partly because it's homework, and partly because I hate w

Cant display mysql data
Hey all,

I am learning php and my first goal is to create a simple CMS. At the moment I am st

Why is my row count 0?
Here's the MySQL query i'm running. It basically pulls data from 2 tables based on some data passed.

Rounding a number queried from a database
I know that to display a rounded number you just do echo "round($number)";. But how would

Re-Order by ID Number
I have a cms set up for inputting an image, thumb, title, pdf, and eps. When input the database ass

str_replace help
I am thinking str_replace is my only option to filter outputs from my database to convert them to sa

foreach loop, assistance request
I would like some guidance on the usage of foreach as I try to parse through a large database and wh

Sign up to write
Sign up now if you have flare of writing..
Login   |   Register
Follow Us
Indyaspeak @ Facebook Indyaspeak @ Twitter Indyaspeak @ Pinterest RSS



Play Free Quiz and Win Cash