Unknown Syntax Error

The compiler tells us that there is a syntax error on line #9. We cannot seem to find any problems with the code that should cause this error. This is a screenshot of the code:Code screenshot.

You’re declaring variable “i” inside the for loop initializer. That’s not allowed in C (only C++). Take out the word “int” from that line, and add an “int i;” above it and it should work.

Actually I believe you will find the int i; needs to be at the very top, just inside the main() function. This is certainly the case with C18 and I believe EasyC is actually just a pretty front end to C18

Yes, that’s correct and what I meant, but I wasn’t very clear about where “above it” really meant.

EasyC is just a Drag and Drop front end for MCC18.
MCC18 is (mostly) ANSI 1989 compliant.

Declaring a Variable inside the For Loop (or any other place a Variable is Initialized, other than at the Very Top of the Scope) is not allowed. The Scope being differentiated by { and }.

C++ and (IRRC ANSI 1999) allow this usage for Variable Declaration…

For example, MCC18 will allow this because each Variable Declaration occurs at the top of a Scope:

int test_function()
{
    int forty_two = 42;

    forty_two++;

    {
        int ninety_nine = 99;

        ninety_nine--;

        {
            int eighty_six = 86;
            eighty_six += ninety_nine;

            {
                int thirteen = 13;
                thirteen--;
            }
        }
    }
}

Quill’s Code would need to be written like this:

#include "Main.h"

void accel(int targetVelocity)
{
    int iC;
    int i;
    
    if(targetVelocity > 130)
    {
        for(i=127;i<targetVelocity;i+=20)
        {
            iC=127+(127-i);
            SetPWM(5,i);
            SetPWM(6,iC);
            Wait(100);
        }
    }
    .....
    .....        

or could be written like this:

#include "Main.h"

void accel(int targetVelocity)
{
    int iC;
    
    if(targetVelocity > 130)
    {
        int i;
        for(i=127;i<targetVelocity;i+=20)
        {
            iC=127+(127-i);
            SetPWM(5,i);
            SetPWM(6,iC);
            Wait(100);
        }
    }
    .....
    .....        

Qwill,
While you’re tuning your code, I suggest you correct the variable name spelling error in line 27.
Eric