Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Dec 15, 2006, 12:04 PM   #1
bronxbomber92
macrumors regular
 
Join Date: Nov 2006
Error, is GCC complaining for no reason?

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

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

Thanks for any help!

Last edited by bronxbomber92; Dec 15, 2006 at 12:14 PM.
bronxbomber92 is offline   0 Reply With Quote
Old Dec 15, 2006, 12:09 PM   #2
iMeowbot
macrumors 601
 
iMeowbot's Avatar
 
Join Date: Aug 2003
The whole file would be helpful. An error at the end of file quite often comes from a typo much earlier on.
iMeowbot is offline   0 Reply With Quote
Old Dec 15, 2006, 12:16 PM   #3
Palad1
macrumors 6502a
 
Palad1's Avatar
 
Join Date: Feb 2004
Location: 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.
Palad1 is offline   0 Reply With Quote
Old Dec 15, 2006, 12:45 PM   #4
bronxbomber92
Thread Starter
macrumors regular
 
Join Date: Nov 2006
Here's the file: http://rafb.net/paste/results/3H6gm080.html
bronxbomber92 is offline   0 Reply With Quote
Old Dec 15, 2006, 01:08 PM   #5
iMeowbot
macrumors 601
 
iMeowbot's Avatar
 
Join Date: Aug 2003
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.

Last edited by iMeowbot; Dec 15, 2006 at 01:30 PM.
iMeowbot is offline   0 Reply With Quote
Old Dec 15, 2006, 01:28 PM   #6
jeremy.king
macrumors 603
 
jeremy.king's Avatar
 
Join Date: Jul 2002
Location: Fox Lake, IL
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: */
jeremy.king is offline   0 Reply With Quote
Old Dec 15, 2006, 01:53 PM   #7
iSee
macrumors 68040
 
iSee's Avatar
 
Join Date: Oct 2004
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. 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?
iSee is offline   0 Reply With Quote
Old Dec 15, 2006, 02:08 PM   #8
jeremy.king
macrumors 603
 
jeremy.king's Avatar
 
Join Date: Jul 2002
Location: Fox Lake, IL
Hey can you post SDL.h too? I am playing with Eclipse CDT to see what it complains about...
jeremy.king is offline   0 Reply With Quote
Old Dec 15, 2006, 02:16 PM   #9
iMeowbot
macrumors 601
 
iMeowbot's Avatar
 
Join Date: Aug 2003
SDL is here, the runtime framework should have enough to build.
iMeowbot is offline   0 Reply With Quote
Old Dec 15, 2006, 02:18 PM   #10
jeremy.king
macrumors 603
 
jeremy.king's Avatar
 
Join Date: Jul 2002
Location: Fox Lake, IL
Quote:
Originally Posted by iMeowbot View Post
SDL is here, the runtime framework should have enough to build.
Thanks.
jeremy.king is offline   0 Reply With Quote
Old Dec 15, 2006, 02:30 PM   #11
bronxbomber92
Thread Starter
macrumors regular
 
Join Date: Nov 2006
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
bronxbomber92 is offline   0 Reply With Quote
Old Dec 15, 2006, 02:40 PM   #12
savar
macrumors 68000
 
savar's Avatar
 
Join Date: Jun 2003
Location: District of Columbia
Send a message via AIM to savar
Quote:
Originally Posted by iMeowbot View Post
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.
__________________
Mehce
savar is offline   0 Reply With Quote
Old Dec 15, 2006, 03:28 PM   #13
bousozoku
Moderator emeritus
 
Join Date: Jun 2002
Location: Gone but not forgotten.
Quote:
Originally Posted by bronxbomber92 View Post
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
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.
bousozoku is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
Where is my gcc and g++ compiler sysProgrammer Mac Programming 10 Nov 24, 2013 07:47 PM
All iPads: Why is everyone complaining? yinz iPad 37 Oct 23, 2013 06:01 AM
What would reason be for this happening? (no mountable file systems error) 2012Tony2012 Mac Applications and Mac App Store 0 Mar 12, 2013 07:43 PM
iPad: "Cannot connect to iTunes Store" error for no reason Axmann iPad 5 Dec 26, 2012 04:24 AM
GCC in Mountain Lion jojo0815 OS X 10.8 Mountain Lion 6 Jul 31, 2012 09:51 AM

Forum Jump

All times are GMT -5. The time now is 10:53 PM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC