I have this test code for the game programming library allegro.

Code:
#include <allegro.h>
#include <stdio.h>

int i;

int main()
{
   allegro_init();
   set_gfx_mode(GFX_AUTODETECT, 640, 480, 0, 0);
    printf("Hello World");
   for i<10000;
   {
      i++;
   }
    return 0;
}
END_OF_MAIN()


When ran I get a syntax error about the i variable. plz help.
You never declare it. You need to do int i;.

EDIT: Wait, I see it at the top there, I missed it. You'll want to give it an initial value, though. It's for for loop. for(<initialization>; <condition>; <increment>) { ... } so:

Code:

for (i = 0; i < 1000; i++) { ... }
To implement a delay in Allegro you may wish to look at its timer functions; that loop will run incredibly quickly, and an optimising compiler should replace it with i = 10000; in any case.
adept wrote:
I have this test code for the game programming library allegro.
...
When ran I get a syntax error about the i variable. plz help.


Quick tip: don't make variables global unless you have a good reason to (i.e. put the "int i;" statement in main.)
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement