Go Down

Topic: } Error with code (Read 3076 times) previous topic - next topic

TTD03

Hi there, am having an issue with a code that was working before.( Is attached),and I have a new modified version,(is attached as well) and am getting this error...

"NoLimits2RCS_DD_demo.ino: In function 'void loop()':
NoLimits2RCS_DD_demo:240: error: expected `}' at end of input
NoLimits2RCS_DD_demo:240: error: expected `}' at end of input"

I have scanned the script multiple times and I cannot find the culprite that is causing the error.
Any help would be appreciated!
Thanks!

dannable

What is the target device?
Beginners guide to using the Seeedstudio SIM900 GPRS/GSM Shield

TTD03

Hi there, am having an issue with a code that was working before.( Is attached),and I have a new modified version,(is attached as well) and am getting this error...

"NoLimits2RCS_DD_demo.ino: In function 'void loop()':
NoLimits2RCS_DD_demo:240: error: expected `}' at end of input
NoLimits2RCS_DD_demo:240: error: expected `}' at end of input"

I have scanned the script multiple times and I cannot find the culprite that is causing the error.
Any help would be appreciated!
Thanks!
Like the Arduino?
It's an Arduino Leonardo connected on COM 3.

PaulS

If you put each { on a new line, and properly indented the code in between the { and it's matching }, you'd see the problem immediately.
The art of getting good answers lies in asking good questions.

Robin2

Has this anything to do with your other Thread  ?

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

TTD03

^^ I'm sorry to say I am not a very experienced coder, my friend wrote the script and I've been modifying the script ever since and it has been going alright. But in an instance like this, where my ability is not sufficient enough, I cannot figure it out. If you have found the problem, please share. Thank you.

^ Nope Robin, that issue got solved, completely different issue but same basic code.

SurferTim

When I started coding, I used this format. The opening and closing brackets are indented the same.
Code: [Select]
if (RestraintHX != RestraintPOS)
{  //If restraint button has moved...
  delay (100); //Delay 100ms
  if (RestraintPOS == LOW)
  { //If restraint button in close position...
    RestraintHX = RestraintPOS;
  } //Save new button value
  else
  { //If restraint button in open position...
    RestraintHX = RestraintPOS;
  } //Save new button value
}

UKHeliBob

Quote
When I started coding, I used this format. The opening and closing brackets are indented the same.
What format do you use now, and why ?
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

TTD03

#8
Oct 20, 2014, 11:47 pm Last Edit: Oct 20, 2014, 11:53 pm by TTD03
^^ I see you grabbed that from the original version which worked.
What is there now is this.
Code: [Select]
if (RestraintHX != RestraintPOS)
{  //If restraint button has moved...
  delay (100); //Delay 100ms
  if (RestraintPOS == LOW){ //If restraint button in close position...
   
   
    RestraintHX = RestraintPOS;} //Save new button value
  else{ //If restraint button in open position...
   
    RestraintHX = RestraintPOS;} //Save new button value
}



Is this the part I messed up and not seeing it? Or is it something else that I missed?

Thanks!

SurferTim

@UKHeliBob: I use this now. But there are "helpers" now that highlight the matching opening or closing bracket if you select one. That was not available when Moses and I were sitting around the burning bush learning C with TurboC v1.0. ;)
Code: [Select]
if (RestraintHX != RestraintPOS) {  //If restraint button has moved...
  delay (100); //Delay 100ms
  if (RestraintPOS == LOW)   { //If restraint button in close position...
    RestraintHX = RestraintPOS;
  } //Save new button value
  else { //If restraint button in open position...
    RestraintHX = RestraintPOS;
  } //Save new button value
}

TTD03

^ Am so confused, I see what you changed, but what was wrong with mine?

SurferTim

What is wrong with yours is you can't see the matching opening and closing brackets, and you are missing at least one.

Here is an example of what I recommend for you:
Code: [Select]
void function()
{
    if(first if)
    {
        if(embedded if)
        {

        }
        else // this indent matches the embedded if, and so do the following brackets
        {

        }
    }
    else // this indent matches first if and the following brackets do also
    {

    }
} // this is the closing bracket for the function

Note how easy it is to see a missing bracket?

TTD03

Damn, so easy, end of the code, was missing closing brackets, now the code works, how could I have missed that before :/

Edit 1:
I decided to start with my original version again and do the same modifications and be more careful about brackets, sure enough, did my changes,  not 1 error. Turns out I had deleted 4-5 brackets while modifying the first time.

Edit 2:

Another question:
If you take a look in the Original Version.ino file and look at this part (Near line 190)
Why are there 3 closing brackets? I understand the 2 inner closing brackets but the last and most outer closing bracket specifically on line 202, I can't figure out what that closing bracket is closing. I tried the highlighting thing where you highlight one bracket and then the other highlights, but it is no where to be found. Any help is appreciated, thanks everyone, you guys rock!

PaulS

Quote
If you take a look in the Original Version.ino file and look at this part (Near line 190)
Why are there 3 closing brackets?
You'll need to figure that out for yourself. Your positioning of open and close curly braces absolutely sucks.
The art of getting good answers lies in asking good questions.

TTD03

Quote
If you take a look in the Original Version.ino file and look at this part (Near line 190)
Why are there 3 closing brackets?
You'll need to figure that out for yourself. Your positioning of open and close curly braces absolutely sucks.
I'll let my friend know :P He wrote it.
I figured it out after all. It was way up high in the code.
Thanks for helping everyone!

Go Up