PDA

View Full Version : Error, is GCC complaining for no reason?




bronxbomber92
Dec 15, 2006, 11:04 AM
Hey, I'm getting this error: "parse error at en of input"
It's on my last line of code. I've had this error before, just I can't remember how I fixed :confused:

I think the problem is more of GCC just being picky, then the actual code.

Here's the code at the end of the file:
void save_options(void)
{
FILE * fi;
char fname[512];

if (getenv("HOME") != NULL)
{
snprintf(fname, sizeof(fname), "%s/.defendguinrc", getenv("HOME"));

fi = fopen(fname, "w");

if (fi != NULL)
{
fprintf(fi, "# Defendguin Options File\n\n");
fprintf(fi, "CONFIG_EFFECTS_VOLUME = %d\n", vol_effects);
fprintf(fi, "CONFIG_MUSIC_VOLUME = %d\n", vol_music);
fprintf(fi, "CONFIG_JOY_FIRE = %d\n", joy_fire);
fprintf(fi, "CONFIG_JOY_BOMB = %d\n", joy_bomb);
fprintf(fi, "CONFIG_JOY_X = %d\n", joy_x);
fprintf(fi, "CONFIG_JOY_Y = %d\n", joy_y);
fprintf(fi, "SCORE_LAST_1 = %d\n", score[0]);
fprintf(fi, "SCORE_LAST_2 = %d\n", score[1]);
fprintf(fi, "LEVEL_LAST_1 = %d\n", level[0]);
fprintf(fi, "LEVEL_LAST_2 = %d\n", level[1]);
fprintf(fi, "SCORE_HIGH = %d\n", highscore);

fclose(fi);
}
}

} If needed, I'll upload the file. It's about 5,500 lines of code, so I can't paste it all here :p

Thanks for any help!



iMeowbot
Dec 15, 2006, 11:09 AM
The whole file would be helpful. An error at the end of file quite often comes from a typo much earlier on.

Palad1
Dec 15, 2006, 11:16 AM
When I get this error, I usually check my included headers file.

Most of the time, I forgot some curly brace or semicolumn in my typedefs.

bronxbomber92
Dec 15, 2006, 11:45 AM
Here's the file: http://rafb.net/paste/results/3H6gm080.html

iMeowbot
Dec 15, 2006, 12:08 PM
Somewhere in function game() you are missing a few closing curly braces. I'd try to figure out where, but my brain exploded when I saw that a single function was 3000 lines.

Seriously, function calls in modern C are cheap. Try to make more use of them, it will make life much easier.

jeremy.king
Dec 15, 2006, 12:28 PM
My guess has to do with the two ifs on lines 1063 and 1073, notice the indentation is all screwy there, indicating that perhaps you didn't close the if on 1063???


if ((left_down == 1 || (thrust_down == 1 &&
dir[player] == DIR_LEFT)) &&
dying[player] == 0 &&
dancing[player] == 0)
{
/* Increase our left speed: */

if (xm[player] > -16)
xm[player] = xm[player] - 2;

if ((right_down == 1 || (thrust_down == 1 &&
dir[player] == DIR_RIGHT)) &&
dying[player] == 0 &&
dancing[player] == 0)
{
/* Increase our right speed: */

iSee
Dec 15, 2006, 12:53 PM
If I understand the intent of the code, you need to insert two end-curly braces at about 1090 (and fix the indenting at 1077-1089).

Also, thanks for the chuckle. :D I don't think I've ever had a source file this long, and definitely no 3K line functions. But the code is really clean, straightforward and well commented, so I can't really critisize your organization.

By the way, are you going to post a link you your game when its done (well, playable) so we can all check it out? :)

jeremy.king
Dec 15, 2006, 01:08 PM
Hey can you post SDL.h too? I am playing with Eclipse CDT to see what it complains about...

iMeowbot
Dec 15, 2006, 01:16 PM
SDL is here (http://www.libsdl.org/download-1.2.php), the runtime framework should have enough to build.

jeremy.king
Dec 15, 2006, 01:18 PM
SDL is here (http://www.libsdl.org/download-1.2.php), the runtime framework should have enough to build.

Thanks.

bronxbomber92
Dec 15, 2006, 01:30 PM
Thanks for the help guys :) I'll check out each place spot all of you pointed out.

I must be honest though. I didn't write most of this (I'm more of a C++ guy). I'm trying to port this game just for the heck of it :P... I'll post a download link when finished though :)

Edit - I fixed the the problem. When I earlier went through all the code so I didn't need the sounds I deleted some extra braces. Stupid mistakes on my end. Now I need to properly load each image >.< Which will be hassle, but oh well.

With Xcode, and using paths like "image/loader/loader.bmp" I know it gets all screwed up, so you need a "true" path to the image file. How would I do this, as Xcode makes image loading all screwy :p

savar
Dec 15, 2006, 01:40 PM
Somewhere in function game() you are missing a few closing curly braces. I'd try to figure out where, but my brain exploded when I saw that a single function was 3000 lines.

Seriously, function calls in modern C are cheap. Try to make more use of them, it will make life much easier.

This post cracked me up. I took a look at the code and it's kinda terrifying. I predict this being featured on thedailywtf.com.

bousozoku
Dec 15, 2006, 02:28 PM
Thanks for the help guys :) I'll check out each place spot all of you pointed out.

I must be honest though. I didn't write most of this (I'm more of a C++ guy). I'm trying to port this game just for the heck of it :P... I'll post a download link when finished though :)

Edit - I fixed the the problem. When I earlier went through all the code so I didn't need the sounds I deleted some extra braces. Stupid mistakes on my end. Now I need to properly load each image >.< Which will be hassle, but oh well.

With Xcode, and using paths like "image/loader/loader.bmp" I know it gets all screwed up, so you need a "true" path to the image file. How would I do this, as Xcode makes image loading all screwy :p

It's often typical in C coding to comment sections of code, rather than deleting them. Modern programming editors will often allow you to select text and use a function to do exactly that. It might help you in the future.