Thread: Tic-Tac-Toe help

  1. #1
    Registered User
    Join Date
    Oct 2008
    Posts
    13

    Tic-Tac-Toe help

    Ive been trying to clean this program up but can't figure out these past two things. When I try to compile it I get a message saying in function gameloop, board is undeclared. I also get a warning saying from function computersMove saying passing arg 1 of `findWin' , `getCorner', and 'getSide' makes pointer from integer without a cast. Any help would be GREAT

    Thanks

  2. #2
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    Well, board is declared in main, but you're trying to use it in
    Code:
    void gameLoop(void)
    which doesn't know anything about main()'s local variables.

    It would probably be a good idea to pass in board to this function, something like this:
    Code:
    /* in main() */
    gameLoop(board);
    
    void gameLoop(char board[][3])
    {
    /* ... */
    The same thing goes for computersMove() and any other functions that need board.

    I see now that you're passing board into most of your functions, but you're calling it gameBoard. Just use the same name.

    Or you could make board global, but I strongly recommend against that.

    Oh, and consider using for loops to implement findWin().
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  3. #3
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Well.

    This is because you declare board in main, so it does not exist globally. You make this mistake (assuming that board is global) quite a few times, so I'm surprised you got this far without realizing there's a problem.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  4. #4
    Registered User
    Join Date
    Oct 2008
    Posts
    13
    thanks, I got the board declaration thing fixed but still have problems with the pointer from integer without a cast thing. Any help would be.......well helpful

  5. #5
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Posting the line(s) where this error is reported at would help quite a bit.

    Most of the time it's because there is no prototype for the function, so the compiler assumes that the return value is an integer, and you are using it to assign into a pointer. E.g.
    Code:
    char *p;
    ...
      p = somefunc();
    ...
    
    char *somefunc();
    The same thing can happen if you forget a header-file.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  6. #6
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    That means you are still not passing the gameboard around, but some other variable.

  7. #7
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by matsp View Post
    Posting the line(s) where this error is reported at would help quite a bit.
    You could even rework your program based on the corrections you've made so far and post it (and remember to post the actual error too).
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  8. #8
    Registered User
    Join Date
    Oct 2008
    Posts
    13
    got it thanks guys

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help me with my simple Tic tac toe prog
    By maybnxtseasn in forum C Programming
    Replies: 2
    Last Post: 04-04-2009, 06:25 PM
  2. tic tac toe crashes :(
    By stien in forum Game Programming
    Replies: 4
    Last Post: 05-13-2007, 06:25 PM
  3. Help with Tic Tac Toe game
    By snef73 in forum C++ Programming
    Replies: 1
    Last Post: 04-25-2003, 08:33 AM
  4. Need some help with a basic tic tac toe game
    By darkshadow in forum C Programming
    Replies: 1
    Last Post: 05-12-2002, 04:21 PM
  5. Tic Tac Toe Help
    By aresashura in forum C++ Programming
    Replies: 1
    Last Post: 11-21-2001, 12:52 PM