Syntax Error

Posted By: alwaysblack

Syntax Error - 08/16/09 15:59

Can anyone see why these lines fail to compile with a syntax error?

char* data = {'A','B','C','D','E','F','G','H','I','J'};
int pointer = {0,1,2,3,4,5,6,7,8,9};


If there's nothing wrong with the actual syntax (I can't see anything), what other reason could there be for a syntax error compiling with Lite C?
Posted By: MrGuest

Re: Syntax Error - 08/16/09 16:04

you haven't specified that size of the array
int data[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
Posted By: alwaysblack

Re: Syntax Error - 08/16/09 16:07

Ah, thank you.

I took the lines from a tutorial about lists here: http://www.opserver.de/coni_users/web_users/pirvu/au/tutorials.html

I guess either the author forgot or else is using something with a different syntax.
Posted By: alwaysblack

Re: Syntax Error - 08/23/09 11:37

Argh. Another one, although less basic, I think.
Code:
//a function to visualize an item on a panel
void item_visualize( Inventory *inventory, Panel *panel ) {
panel->bmap = inventory->image;
}


Posted By: Saturnus

Re: Syntax Error - 08/23/09 11:46

If "Panel" is meant to be the predefined acknex struct, which is named "PANEL", it should be "PANEL *panel" instead of "Panel *panel".
Posted By: EvilSOB

Re: Syntax Error - 08/23/09 11:48

As Kombucha says. Pretty much everything in Lite-C is case-sensitive...
Posted By: alwaysblack

Re: Syntax Error - 08/23/09 11:54

I tried that, no luck frown

Here's the rest of the file in case it matters...

Code:
////////////////////////////////////////////////////////////////////
//
//		Theseus Engine V1.0
//
////////////////////////////////////////////////////////////////////

#include <acknex.h>
#include <default.c>
#include <litec.h>

//ROOM.c

typedef struct 
{
  int roomNumber;
  BMAP* image;
  STRING* name;

} ROOM;

/*
//a function to visualize an room on a panel
void room_visualize(DUNGEON* dungeon, PANEL* panel)
{
  panel->bmap = dungeon->image;
}
*/

//a function to visualize an item on a panel
void item_visualize( Inventory* inventory, PANEL* panel ) {
  panel->bmap = inventory->image;
}


//ROOM creation function, returns pointer to the newly created ROOM
ROOM* room_create( int number, String* imageName ) 
{
  ROOM* room = malloc( sizeof( ROOM ) );
  
  //always fill ALL the room's properties immediately after!
  room->roomNumber = number;
  room->image = bmap_create( imageName );
  room->name = imageName;
  
  return room; //return the new room back
}


//function to remove an room
void room_remove( ROOM* room ) 
{
  ptr_remove( room->image ); //remove bitmap first
  ptr_remove( room->name ); //remove name
  free( room ); //THEN remove room
}


Posted By: EvilSOB

Re: Syntax Error - 08/23/09 12:11

Well, try completeing your code before compiling it.
At a glance I can see that neither "DUNGEON" nor "Inventory"
types exist yet. (ie you haven defined their structs yet)

So wither there is still some code missing, you you need to define
your structs for "DUNGEON" and "Inventory" types before anything
will even get close to compiling, let alone working.
Posted By: alwaysblack

Re: Syntax Error - 08/23/09 12:24

OK, apologies, I was trying to avoid flooding the board with files if it was just another simple misunderstanding of syntax on my part.

To present a fuller explanation... I'm trying to get Joozey's 'structured programming' example to work, firstly to try and understand what's happening and secondly to maybe tweak the principles he introduced to suit my own project.

Here are all of the files.

The 'room' definition -

Code:
//ROOM.c

typedef struct 
{
  int roomNumber;
  BMAP* image;
  STRING* name;

} ROOM;


//a function to visualize an room on a panel
void room_visualize(DUNGEON* dungeon, PANEL* panel)
{
  panel->bmap = dungeon->image;
}


//ROOM creation function, returns pointer to the newly created ROOM
ROOM* room_create( int number, String* imageName ) 
{
  ROOM* room = malloc( sizeof( ROOM ) );
  
  //always fill ALL the room's properties immediately after!
  room->roomNumber = number;
  room->image = bmap_create( imageName );
  room->name = imageName;
  
  return room; //return the new room back
}


//function to remove an room
void room_remove( ROOM* room ) 
{
  ptr_remove( room->image ); //remove bitmap first
  ptr_remove( room->name ); //remove name
  free( room ); //THEN remove room
}



The 'dungeon' definition -

Code:
//DUNGEON.c
typedef struct 
{  
  bool alive;

  Panel *panel;

  ROOM *item1;
  ROOM *room2;
  
} DUNGEON;


//function to keep the inventory running and catch input
void inventory_run( DUNGEON *inventory ) 
{
    //infinite loop
  //in order to check if the object still exists and prevent empty pointer errors,
  //you can best add an "alive" state, just add an "alive" boolean in the structure, and check it here
  //after the while, call the inventory_remove function to fully destroy
  //We simply make an inventory_kill() function, and set the boolean to false to kill the object
  while( inventory->alive ) { //as long as the inventory is alive, keep loopin'

    //when we press key_1, show room1
    if( key_1 ) 
    {
      room_visualize( inventory->room1, inventory->panel ); //remember this function in the room code?
    }

    //when we press key_2, show room2
    if( key_2 ) 
    {
      room_visualize( inventory->room2, inventory->panel );
    }

    wait( 1 );
  }

  inventory_remove( inventory ); //the object is dead, remove it!
}


//function kill
void dungeon_kill( DUNGEON *dungeon ) 
{
  dungeon->alive = false;
}


//function to create a new dungeon
DUNGEON *dungeon_create() 
{
  //allocate new dungeon structure
  DUNGEON *dungeon = malloc( sizeof( DUNGEON ) );
 
  //once again, fill all its parameters immediately after
  dungeon->alive = true; //we set this object to alive first!
  dungeon->panel = pan_create("bla");
  dungeon->room1 = room_create( 1, "room1.tga" ); //easily create an room
  dungeon->room2 = room_create( 2, "room2.tga" );

  //in addition to the room code, the dungeon code catches player input
  //this run function handles this input, and loops infinitely
  dungeon_run( dungeon );

  return dungeon; //give back the dungeon
}


void dungeon_remove( DUNGEON *dungeon ) 
{
  room_remove( dungeon->room1 ); //remove room1 first
  room_remove( dungeon->room2 ); //remove room2
  ptr_remove( dungeon->panel ); //don't forget to remove the panel too
  free( dungeon ); //THEN remove dungeon safely
}



The main -

Code:
////////////////////////////////////////////////////////////////////
//
//		Theseus Engine V1.0
//
////////////////////////////////////////////////////////////////////

#include <acknex.h>
#include <default.c>
#include <litec.h>


#include "panels.c"
#include "room.c"
#include "dungeon.c"
////////////////////////////////////////////////////////////////////

void main() 
{

  //create a new inventory!
  DUNGEON *dungeon = dungeon_create();

  //main loop (a little dirty, but forgiveable for now :) )
  while( 1 ) {
    
    //when we press q, remove the inventory
    if( key_q ) 
    {
      dungeon_remove( dungeon ); //this should go smooth without errors...
    }

    wait( 1 );
  }
}



As you can see, I have just taken Joozey's example files and renamed the objects to suit the purpose for which I intend to develop them. Joozey's unedited files give a syntax error in the same place, when I compile main.

Code:
Error in 'room.c' line 20: syntax error

<void item_visualize( Inventory* inventory, PANEL* panel ) {
>

.
Can't compile MAIN.C




Posted By: EvilSOB

Re: Syntax Error - 08/23/09 13:20

Originally Posted By: alwaysblack
OK, apologies, I was trying to avoid flooding the board with files if it was just another simple misunderstanding of syntax on my part.
Dont worry about that, just use the [spoiler] code to 'hide' thecode from regular view.
After all, if you dont post code, ... , how can we STEAL it!

But anyways, I think I see the problem, but Im not sure. With your problem code...
Code:
//a function to visualize an item on a panel
void item_visualize( Inventory *inventory, Panel *panel ) {
panel->bmap = inventory->image;
}

I STILL cant find a struct for your "Inventory" type.
And looking at the rest of your code is tricky, cause your 'changed' type-names are a little odd and confusing.
But I THINK this code should be
Code:
//a function to visualize an item on a panel
void item_visualize( DUNGEON *inventory, Panel *panel ) {
panel->bmap = inventory->image;
}


Let me know how that goes...
Posted By: alwaysblack

Re: Syntax Error - 08/23/09 17:43

No joy! frown

Think I'll start from scratch in a new thread. Trying to learn too much at once, I think.
Posted By: alwaysblack

Re: Syntax Error - 08/23/09 17:44

P.S. Hehe, 'steal' my code? Doubt that will be of any use to you! Hiding from embarassment more like!
© 2023 lite-C Forums