2 registered members (TipmyPip, AndrewAMD),
12,726
guests, and 5
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Syntax Error
#285005
08/16/09 15:59
08/16/09 15:59
|
Joined: Aug 2009
Posts: 11
alwaysblack
OP
Newbie
|
OP
Newbie
Joined: Aug 2009
Posts: 11
|
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?
|
|
|
Re: Syntax Error
[Re: alwaysblack]
#285006
08/16/09 16:04
08/16/09 16:04
|
Joined: Jul 2008
Posts: 1,178 England
MrGuest
Serious User
|
Serious User
Joined: Jul 2008
Posts: 1,178
England
|
you haven't specified that size of the array int data[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
|
|
|
Re: Syntax Error
[Re: Saturnus]
#286139
08/23/09 11:48
08/23/09 11:48
|
Joined: Feb 2008
Posts: 3,232 Australia
EvilSOB
Expert
|
Expert
Joined: Feb 2008
Posts: 3,232
Australia
|
As Kombucha says. Pretty much everything in Lite-C is case-sensitive...
"There is no fate but what WE make." - CEO Cyberdyne Systems Corp. A8.30.5 Commercial
|
|
|
Re: Syntax Error
[Re: alwaysblack]
#286145
08/23/09 12:11
08/23/09 12:11
|
Joined: Feb 2008
Posts: 3,232 Australia
EvilSOB
Expert
|
Expert
Joined: Feb 2008
Posts: 3,232
Australia
|
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.
"There is no fate but what WE make." - CEO Cyberdyne Systems Corp. A8.30.5 Commercial
|
|
|
Re: Syntax Error
[Re: EvilSOB]
#286146
08/23/09 12:24
08/23/09 12:24
|
Joined: Aug 2009
Posts: 11
alwaysblack
OP
Newbie
|
OP
Newbie
Joined: Aug 2009
Posts: 11
|
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 -
//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 -
//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 -
////////////////////////////////////////////////////////////////////
//
// 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.
Error in 'room.c' line 20: syntax error
<void item_visualize( Inventory* inventory, PANEL* panel ) {
>
.
Can't compile MAIN.C
Last edited by alwaysblack; 08/23/09 12:26.
|
|
|
Re: Syntax Error
[Re: alwaysblack]
#286148
08/23/09 13:20
08/23/09 13:20
|
Joined: Feb 2008
Posts: 3,232 Australia
EvilSOB
Expert
|
Expert
Joined: Feb 2008
Posts: 3,232
Australia
|
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...
//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
//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...
"There is no fate but what WE make." - CEO Cyberdyne Systems Corp. A8.30.5 Commercial
|
|
|
Moderated by mk_1, Perro, rayp, Realspawn, Rei_Ayanami, rvL_eXile, Spirit, Superku, Tobias, TSG_Torsten, VeT
|