Hi All,
I'm a beginner in C and C++, and I get a "Stack Overflow" problem when I compile my code. I use visual studio 2008.
My code uses some library, that has some header files, and some .cpp files. The library basically helps me in getting a random number from a uniform discrete distribution.
My code (a file called program.cpp) and the .cpp and .h files of the library I'm using are all included in the attached .zip file.
Any help will be really appreciated!
And for convenience, the contents of my main code are:
#include <fstream>
#include <iostream>
#include <stdio.h>
#include <string>
#include <cstdlib>
using namespace std;
#define WANT_STREAM
#define WANT_MATH
#define WANT_TIME
#include "include.h"
#include "newran.h"
#include "tryrand.h"
#ifdef use_namespace
using namespace NEWRAN;
#endif
#define N 3499
#define start 0
int main (void)
{
//int tmp;
//int s;
//int count;
ofstream fout("input.dat");
Real probs[N];
Real val[N];
for(int i=0;i<N;i++)
{
probs[i]=1/(float)N;
val[i]=start+i;
}
DiscreteGen discrete(N,probs,val);
srand ( time(NULL) );
double mySeed=(double)rand()/RAND_MAX;
//cout<<mySeed<<endl;
discrete .Set (mySeed);
//Sleep(2000);
int a[9000][9900];
//for (ttt=0;ttt<100;ttt++){
//fout<<"[";
////discrete.Set(0.02);
//for (uuu=0; uuu<1000; uuu++){
//fout << discrete.Next() <<" ";
//}
//fout<<"]";
//}
//fout<<"];";
int i=0;
while(i<1000){
fout<<"[";
int k=discrete.Next();
int j=discrete.Next();
int p=discrete.Next();
int l=discrete.Next();
int v=discrete.Next();
for (int e=0;e<3500;e++){
if(e==k || e==j || e==p ||e==l ||e==v){
a[i][e]=1;
}
else {
a[i][e]=0;
}
fout<<a[i][e];
fout<<" ";
}
fout<<"] ";
fout<<"[";
int t=discrete.Next();
int y=discrete.Next();
int q=discrete.Next();
int s=discrete.Next();
int z=discrete.Next();
int w=discrete.Next();
for (int e=0;e<3500;e++){
if(e==t || e==y || e==q ||e==s ||e==z || e==q){
a[i+1][e]=1;
}
else {
a[i+1][e]=0;
}
fout<<a[i][e];
fout<<" ";
}
fout<<"] ";
fout<<"[";
int mm=discrete.Next();
int jj=discrete.Next();
int pp=discrete.Next();
int ll=discrete.Next();
int vv=discrete.Next();
int gg=discrete.Next();
for (int e=0;e<3500;e++){
if(e==mm || e==jj || e==pp ||e==ll ||e==vv || e==gg){
a[i+2][e]=1;
}
else {
a[i+2][e]=0;
}
fout<<a[i][e];
fout<<" ";
}
fout<<"]";
i=i+3;
}
return 0;
}