Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

bronxbomber92

macrumors regular
Original poster
Nov 23, 2006
109
0
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:
Code:
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

macrumors G3
Aug 30, 2003
8,634
0
The whole file would be helpful. An error at the end of file quite often comes from a typo much earlier on.
 

Palad1

macrumors 6502a
Feb 24, 2004
647
0
London, UK
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.
 

iMeowbot

macrumors G3
Aug 30, 2003
8,634
0
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

macrumors 603
Jul 23, 2002
5,479
1
Holly Springs, NC
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???

Code:
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

macrumors 68040
Oct 25, 2004
3,539
272
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? :)
 

bronxbomber92

macrumors regular
Original poster
Nov 23, 2006
109
0
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

macrumors 68000
Jun 6, 2003
1,950
0
District of Columbia
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

Moderator emeritus
Jun 25, 2002
15,697
1,866
Lard
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.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.