#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    10
    Rep Power
    0

    Question Error: expected declaration specifiers before..


    Hey everyone I find myself having issues with a bug I can't resolve. Perhaps it's something I've overlooked but I'd apreciate some help. The two errors I'm getting are:

    tots.c:9:1: error: expected declaration specifiers before ‘main’
    tots.c:29:1: error: expected declaration specifiers before ‘kid’

    So something is missing in a couple of my important functions. Here's some snippets:

    # include <stdio.h>
    # include <ncurses.h>
    # include <strings.h>
    # include "player.h"
    # include "windows.h"

    //Game Assets

    main()
    {
    struct player p;
    initscr();
    p.b = 'B';
    keypad(stdscr, TRUE);

    p.y = 30;
    p.x = 10;

    //Print the player to the screen

    WINDOW *kidWin;

    mvwprintw(kidWin, p.y, p.x, "%i", (char)p.b );
    wrefresh(kidWin);
    }
    which makes up my entire main piece there, and here's the beginning of the other:

    kid (WINDOW *kidWin, int y, int x, int dir, char n, char c)
    {
    which continues into sprawling code involving mvwprintw actions for the declared window. Of course followed by closed curly brackets acorrdingly. int main(void), int main() and main(void) have all been tried to no avail. I'd appreciate some points regarding this, thanks! :confused:
  2. #2
  3. Contributing User
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jan 2003
    Location
    USA
    Posts
    7,175
    Rep Power
    2222
    What datatypes do main and kid return?

    Also, what language is this? C or C99? C would let you implicitly declare them as returning int, though the compiler should have thrown warnings at you for your sloppiness, but then you aren't even returning anything in main as you had implicitly promised you would. And I don't know whether C99, which borrowed several things from C++, would still allow your implicit declarations as C++ will not allow.

    So explicitly declare main to return int and explicitly return zero at the end of main! And explicitly declare kid to return whatever it's supposed to return.
  4. #3
  5. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,900
    Rep Power
    481
    Arrange your source putting the definition of main at the far end of the file. That way the compiler will know the declaration of kid by the time it needs to know in main.
    [code]Code tags[/code] are essential for python code and Makefiles!
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    10
    Rep Power
    0
    Haha yes the code is admittedly sloppy. I did also try returning 0 in main with no change in the errors. I pretty much stripped stuff down to bare (which is why there are no returns present) in desperation. Here's what's inside kid, just some meat t the control layout in the function below kid that's not having any problems. Oh and this is C.

    while( dir == 0 ) // UP
    {
    mvwprintw(kidWin, y--, x, "%c", n);
    wvmprintw(kidWin, y+2, x, " ");
    wrefresh(kidWin);
    }

    while ( dir == 2) //DOWN
    {
    mvwprintw(kidWin, y++, x, "%c", n);
    mvwprintw(kidWin, (y-2), x, " ");
    wrefresh(kidWin);
    }
    while ( dir == 3 ) //LEFT
    {
    mvwdelch(kidWin, y, x);
    mvwprintw(kidWin, y, x--, "%c", n);
    wrefresh(kidWin);
    while ( dir == 1 ) //RIGHT
    {
    mvwprintw(kidWin, y, x++, "%c", n);
    mvwprintw(kidWin, y, (x-2), " ");
    wrefresh(kidWin);
    }
    @b49P23TIvg that sounds interesting but I'm not exactly sure what you mean by that. Could you elaborate just a little bit further? Thanks for the feedback so far.

    @dwise1_aol I actually read a post on some other thread by you that shed brilliant light on a bad habit I had before. You are a genius, my C skills are feelin hella inadequate.
  8. #5
  9. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,900
    Rep Power
    481
    Code:
    /* compiles without warnings */
    int g(char*,double);
    
    int f(void) {
      return g("favorite constant", 2.9979e8);
    }

    Code:
    /* compiles WITH warnings */
    int f(void) {
      return g("favorite constant", 2.9979e8);
    }
    
    int g(char*,double);
    [code]Code tags[/code] are essential for python code and Makefiles!

IMN logo majestic logo threadwatch logo seochat tools logo