Author Topic: Declaration Specifiers  (Read 2970 times)

0 Members and 1 Guest are viewing this topic.

Offline Fire-MakhTopic starter

  • Beginner
  • *
  • Posts: 2
  • Helpful? 0
Declaration Specifiers
« on: March 15, 2011, 07:52:06 PM »
Every time I try to build my code using the AVR Studio it give me the error


"../test.c:3: error: expected declaration specifiers or '...' before string constant"

What can I do to solve this?

Offline waltr

  • Supreme Robot
  • *****
  • Posts: 1,944
  • Helpful? 99
Re: Declaration Specifiers
« Reply #1 on: March 15, 2011, 08:00:31 PM »
Post the code this error occurred on.

Offline Fire-MakhTopic starter

  • Beginner
  • *
  • Posts: 2
  • Helpful? 0
Re: Declaration Specifiers
« Reply #2 on: March 16, 2011, 07:03:34 AM »
time=20
while(!button_pressed());
printf("Push the button to shut it down")
while(!button_pressed()||time!=0);
   {
   delay_ms(time*1000)
   led_on()
   delay_ms(10)
   led_off()
   time--
   }

I just started and I'm trying to see what works and what doesn't in C

Offline mstacho

  • Supreme Robot
  • *****
  • Posts: 376
  • Helpful? 10
Re: Declaration Specifiers
« Reply #3 on: March 16, 2011, 07:44:11 AM »
Semicolons are essential in C.  They tell the compiler: "I'm done with this command, please move on to the next one".

Check out lines 1, 2 and 3.  You have no semicolon after the printf.  In your second while loop, you should not have the semi-colon there.

In fact, if I get your code properly, you want this to happen:

While it is the case that the button is not pressed
     Continually print: "Push the button to shut it down"

Now, that while loop shouldn't have a semicolon (the semicolon says: "do nothing", and is only useful if you want the code to just wait before doing anything until the condition is met.)

In the second while loop, again no semicolon after it.  It doesn't make much sense to have the !button_pressed() in it, since by that time the button will have been pressed (unless it's an event, I'm not sure how the axon works in this regard).  Here is your code re-written:

int time=20;
while(!button_pressed())
     printf("Push the button to shut it down");
while(!button_pressed()||time!=0)
   {
   delay_ms(time*1000);
   led_on();
   delay_ms(10);
   led_off();
   time--;
   }

It's in C, so that should at least compile...

MIKE
Current project: tactile sensing systems for multifingered robot hands

Offline waltr

  • Supreme Robot
  • *****
  • Posts: 1,944
  • Helpful? 99
Re: Declaration Specifiers
« Reply #4 on: March 16, 2011, 08:18:23 AM »
I thought it was a C syntax issue but we needed to see to code.

Here is a good on-line reference to C:
http://publications.gbdirect.co.uk/c_book/

And here is the book to buy as a reference to all C coding:
http://www.amazon.com/Programming-Language-2nd-Brian-Kernighan/dp/0131103628

Offline joe61

  • Supreme Robot
  • *****
  • Posts: 417
  • Helpful? 16
Re: Declaration Specifiers
« Reply #5 on: March 16, 2011, 08:48:01 AM »
In the second while loop, again no semicolon after it.  It doesn't make much sense to have the !button_pressed() in it, since by that time the button will have been pressed (unless it's an event, I'm not sure how the axon works in this regard).  Here is your code re-written:

int time=20;
while(!button_pressed())
     printf("Push the button to shut it down");
while(!button_pressed()||time!=0)
   {
   delay_ms(time*1000);
   led_on();
   delay_ms(10);
   led_off();
   time--;
   }

It's in C, so that should at least compile...

MIKE

If the "!button_pressed()" is in fact necessary, I think he would want the test to be

while(!button_pressed() && time!=0)

Joe

 

SMF spam blocked by CleanTalk