Error, is GCC complaining for no reason?

Discussion in 'Mac Programming' started by bronxbomber92, Dec 15, 2006.

  1. macrumors regular

    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);
    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!
  2. macrumors G3


    The whole file would be helpful. An error at the end of file quite often comes from a typo much earlier on.
  3. macrumors 6502a


    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.
  4. macrumors regular

  5. macrumors G3


    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.
  6. macrumors 603


    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: */
  7. macrumors 68040


    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? :)
  8. macrumors 603


    Hey can you post SDL.h too? I am playing with Eclipse CDT to see what it complains about...
  9. macrumors G3


    SDL is here, the runtime framework should have enough to build.
  10. macrumors 603


  11. macrumors regular

    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
  12. macrumors 68000


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

    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.

Share This Page