From: blaster2 on
I keep writing this program to model populations and it keeps giving
me an error "Declaration is not allowed here in function main" it
refers to line 47, 48, and 140, it is really confusing and makes no
sense, I am using a Borland compiler for the first time, and this same
code would compile on a linux machine with no problem, here are the
lines of code and a couple of them around it, PLEASE HELP.

*(pMat + i) = 1;
*(Pmat + i) = 1;
//int sect = 0;
//double Hp = 1.0;
double Thandle = 0.01;
int Max = 200;
/*Thandle = MonteCarloPreyPredatorRelation();
Dt = MonteCarloPreyPredatorRelation();
and


i = 0;
FILE *output;
output = fopen("FP3LVMS.txt","w");

fprintf(output, "%f\t%f\n", *(pMat +i), *(Pmat + i));

for( i = 0; i < (Max); i++)
From: ScottMcP [MVP] on
On May 8, 1:59 pm, blaster2 <kstai...(a)iit.edu> wrote:
> I keep writing this program to model populations and it keeps giving
> me an error "Declaration is not allowed here in function main" it
> refers to line 47, 48, and 140, it is really confusing and makes no
> sense, I am using a Borland compiler for the first time, and this same
> code would compile on a linux machine with no problem, here are the
> lines of code and a couple of them around it, PLEASE HELP.
>
>         *(pMat + i) = 1;
>         *(Pmat + i) = 1;
>         //int sect = 0;
>         //double Hp = 1.0;
>         double Thandle = 0.01;
>         int Max = 200;
>         /*Thandle = MonteCarloPreyPredatorRelation();
>         Dt = MonteCarloPreyPredatorRelation();
> and
>
>         i = 0;
>         FILE *output;
>         output = fopen("FP3LVMS.txt","w");
>
>         fprintf(output, "%f\t%f\n", *(pMat +i), *(Pmat + i));
>
>         for( i = 0; i < (Max); i++)

You did not make it clear which lines cause the errors.

At a guess, you are compiling the code as C instead of C++. Old C
compilers require you to declare all local variables before a
function's code begins.
From: Leslie Milburn on

"ScottMcP [MVP]" <scottmcp(a)mvps.org> wrote in message
news:c156087f-f2b3-465c-877d-7a9e1adbbbdb(a)u7g2000vbq.googlegroups.com...

> At a guess, you are compiling the code as C instead of C++. Old C
> compilers require you to declare all local variables before a
> function's code begins.

Scott,
Does this imply that new C compilers allow variable declaration anywhere ? I
haven't tried it myself but I'm just wondering.



From: ScottMcP [MVP] on
On May 8, 8:51 pm, "Leslie Milburn" <CD...(a)NOSPAM.bigpond.com> wrote:
> Scott,
> Does this imply that new C compilers allow variable declaration anywhere ? I
> haven't tried it myself but I'm just wondering.

That's what I have heard in newsgroups. Haven't done C for a couple
of decades myself though.
From: Leslie Milburn on

"ScottMcP [MVP]" <scottmcp(a)mvps.org> wrote...

> Does this imply that new C compilers allow variable declaration anywhere ?
> I
> haven't tried it myself but I'm just wondering.

>> That's what I have heard in newsgroups. Haven't done C for a couple
>> of decades myself though.

Personally this is a feature of C++ I have never liked. I prefer the
discipline of having to declare variables just after the opening brace. The
only exception I do not mind is in tight loops for (int i = 0;....),
anything else just reminds me of the horrors of Level II BASIC where
variables were declared all over the place - very poor programming, IMO.

Anyway, I might have learnt something new today, I'll have to try it out
myself just so I know for sure.
Thanks