Error: expected declaration or statement at end of input

This is a discussion on Error: expected declaration or statement at end of input within the C Programming forums, part of the General Programming Boards category; I'm working on a program that creates a 2 player game of tic tac toe. I know there are mistakes ...

  1. #1
    Registered User
    Join Date
    Nov 2011
    Posts
    2

    Error: expected declaration or statement at end of input

    I'm working on a program that creates a 2 player game of tic tac toe. I know there are mistakes in that the functions don't do exactly what I want them to do, but my question is about the last line of the last funtion, showover. It keeps coming up 'error: expected declaration or statement at end of input' when I run the debugger and I can't work out why. As you can probably see I am not that adept at programming, but any help would be appreciated.

    Code:
    #include <stdio.h>
    #include <stdlib.h> 
    
    
    char display(char db[][3]);                             
    int getrow(char gr_plyr);                               
    int getcol(char gc_plyr);                              
    int validmove(char vb[][3],int vr, int vc);
    void update(char ub[][3],char uplyr, int ur, int uc);   
    int boardfull(char bfb[][3]);                           
    char showover(char sb[][3]);                          
    
    int main(void)
    {
        char board[3][3];                                   
        int row,col;                                        
        char player ='X';                                   
        for(row=0; row<3; row++){
        for(col=0; col<3; col++) board[row][col]='-';       
        do {
            display(board);                                 
            if(player=='X') player='O';
            else player='X';                                
            do {
                row = getrow(player);                       
                col = getcol(player);                      
            } while(!validmove(board,row,col));            
            update(board,player,row,col);                   
        } while(!boardfull(board));                         
                                                            
        char showover(board);                               
        return 0;                                          
    }
    
    char display(char db[][3])
    {
        int c;
        for (c=0;c<3;c++) printf("%c",db[0][c]);
        printf("\n");
        for (c=0;c<3;c++) printf("%c",db[1][c]);
        printf("\n");
        for (c=0;c<3;c++) printf("%c",db[2][c]);
    }
    
    int getrow(char gr_plyr)
    {
        int r;
        printf("Player %c choose your row: ",gr_plyr);
        scanf("%d",&r);
        return r;
    }
    
    int getcol(char gc_plyr)
    {
        int c;
        printf("Player %c choose your column: ", gc_plyr);
        scanf("%d",&c);
        return c;
    }
    
    int validmove(char vb[][3],int vr,int vc)
    {
        if ((vr>0)&(vr<2)&(vc>0)&(vc<2)&(vb[vr][vc]=='-')) return 0;
        else return 1;
    }
    
    void update(char ub[][3],char uplayer,int ur,int uc)
    {
        ub[ur][uc]=uplayer;
    }
    
    int boardfull(char bfb[][3])
    {
        int row, col;
        for (row=0;row<3;row++)
        for (col=0;col<3;col++);
        if (bfb[row][col]!='-') return 1;
        else return 0;
    }
    
    char showover(char sb[][3])
    {
        int c;
        for (c=0;c<3;c++) printf("%c",sb[0][c]);
        printf("\n");
        for (c=0;c<3;c++) printf("%c",sb[1][c]);
        printf("\n");
        for (c=0;c<3;c++) printf("%c",sb[2][c]);
        printf("\nGAME OVER");
        return 0;
    }

  2. #2
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,468
    You're missing a closing curly brace somewhere in main.

    An editor that does auto-indentation will help you find mistakes like this. Also, I find mistakes like this happen more when people squeeze too much stuff on one line. Never put the "then" clause on the same line as the "if" check, and similar for for loops. I also find always using curly braces even if there's one statement helps as well:
    Code:
    if (x < y) print("x is less than y");  // bad
    for (i = 0; i < n; i++) arr[i]=0;  // bad
    
    if (x < y) {
        print("smaller");  // good
    }
    for (i = 0; i < n; i++) {
        arr[i]=0;  // good
    }

  3. #3
    Registered User
    Join Date
    Nov 2011
    Posts
    2
    I got rid of the error and it's compiling, showing the changes that now must be made. Yeah! But thank you.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 3
    Last Post: 04-28-2011, 11:27 PM
  2. Replies: 1
    Last Post: 03-02-2011, 07:07 PM
  3. "Expected declaration or statement at end of input"
    By levitylek in forum C Programming
    Replies: 1
    Last Post: 11-16-2010, 09:02 AM
  4. expected declaration or statement at end of input
    By irelandmc in forum C Programming
    Replies: 5
    Last Post: 06-23-2009, 02:41 AM
  5. Replies: 13
    Last Post: 09-22-2007, 12:07 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21