Solved

I've googled this problem and it seems people who had it messed up their curly braces, but I've checked a couple times and couldn't find anything wrong with my code. Maybe someone can spot something I didn't see or maybe it has nothing to do with braces in my case.

I was trying to make a text based minesweeper, the error is in the last function (all the way at the bottom)

It probably has other errors too since I wrote it fast but I'm just concerned with this one since I can't find the other errors until I fix this one

Code:#include <stdio.h> #include <stdlib.h> #include <time.h> #define MINE 9 #define LOSE 11285 #define WIN 12412 #define FLAG 8233 #define SOLVE 7173 #define ES 5322 //empty space - not part of visible board void displayboard(int board[100][100], int x, int y); void createboard(int board[100][100], int x, int y, int mines); void solvearea(int board[100][100], int dboard[100][100], int x, int y); int main(void) { //ask for board specifications int x = 0, y = 0, mines = 0; printf("Board length: "); scanf("%d", &y); printf("Board width: "); scanf("%d", &x); printf("Amount of mines: "); scanf("%d", &mines); x--; y--; mines--; printf("x: %d y: %d mines: %d\n", x, y, mines); //create the board int board[100][100]; createboard(board, x, y, mines); //initialize display board int dboard[100][100]; int ix, iy; for(ix = 0; ix <= 100; ix++) for(iy = 0; iy <= 100; iy++) dboard[ix][iy] = 0; //main game loop int flag = 0; int mx, my; while(flag != LOSE && flag != WIN){ //flag or move printf("(F)lag or (S)olve:"); scanf("%d", &mx); if(mx == 'F') flag = FLAG; else if(mx == 'S'){ flag = SOLVE; //get move coordinates printf("\nx: "); scanf("%d", &mx); printf("\ny: "); scanf("%d", &my); //do the move if(flag == FLAG){ dboard[mx][my] = 'F'; } else if(board[mx][my] == MINE){ flag = LOSE; } else{ solvearea(board, dboard, mx, my); } displayboard(dboard, x, y); } //print results of game if(flag == LOSE){ printf(" "); printf("Try again next time noob"); } else if(flag == WIN){ printf("grats bro"); } return 0; } void displayboard(int board[100][100], int x, int y){ int ix, iy; for(iy = 0; iy <= y; iy++){ for(ix = 0; ix <= x; ix++){ if(board[ix][iy] == 0) printf("L "); else if(board[ix][iy] == 'F') printf("! "); else if(board[ix][iy] != ES) printf("%d ", board[ix][iy]); } printf("\n\n"); } } void createboard(int board[100][100], int x, int y, int mines){ //initialize board int ix, iy; for(iy = 0; iy <= y; iy++) for(ix = 0; ix <= x; ix++) board[ix][iy] = 0; //create and place mines srand(time(NULL)); int i = 0, mx, my; while(i <= mines){ mx = rand() % (x + 3); my = rand() % (y + 3); if(board[mx][my] != MINE){ board[mx][my] = MINE; i++; } } //create number fields for(iy = 0; iy <= y; iy++){ for(ix = 0; ix <= x; ix++){ if(board[ix][iy] == MINE) continue; else{ if(board[ix+1][iy] == MINE) board[ix][iy]++; if(board[ix-1][iy] == MINE) board[ix][iy]++; if(board[ix][iy+1] == MINE) board[ix][iy]++; if(board[ix][iy-1] == MINE) board[ix][iy]++; if(board[ix+1][iy+1] == MINE) board[ix][iy]++; if(board[ix+1][iy-1] == MINE) board[ix][iy]++; if(board[ix-1][iy+1] == MINE) board[ix][iy]++; if(board[ix-1][iy-1] == MINE) board[ix][iy]++; } } } } //the algorithm in minesweeper that opens up eligible adjacent spaces when you //click on a specific space void solvearea(int board[100][100], int dboard[100][100], int x, int y){ dboard[x][y] = board[x][y]; if(board[x+1][y] == 0){ dboard[x++][y] = 0; if(board[x+1][y] != 0 && board[x+1][y] != ES) dboard[x+1][y] = board[x+1][y]; if(board[x-1][y] != 0 && board[x+1][y] != ES) dboard[x-1][y] = board[x-1][y]; if(board[x][y+1] != 0 && board[x+1][y] != ES) dboard[x][y+1] = board[x][y+1]; if(board[x][y-1] != 0 && board[x+1][y] != ES) dboard[x][y-1] = board[x][y-1]; if(board[x+1][y+1] != 0 && board[x+1][y] != ES) dboard[x+1][y+1] = board[x+1][y+1]; if(board[x+1][y-1] != 0 && board[x+1][y] != ES) dboard[x+1][y-1] = board[x+1][y-1]; if(board[x-1][y+1] != 0 && board[x+1][y] != ES) dboard[x-1][y+1] = board[x-1][y+1]; if(board[x-1][y-1] != 0 && board[x+1][y] != ES) dboard[x-1][y-1] = board[x-1][y-1]; solvearea(board, dboard, x, y); } if(board[x-1][y] == 0){ dboard[x--][y] = 0; if(board[x+1][y] != 0 && board[x+1][y] != ES) dboard[x+1][y] = board[x+1][y]; if(board[x-1][y] != 0 && board[x+1][y] != ES) dboard[x-1][y] = board[x-1][y]; if(board[x][y+1] != 0 && board[x+1][y] != ES) dboard[x][y+1] = board[x][y+1]; if(board[x][y-1] != 0 && board[x+1][y] != ES) dboard[x][y-1] = board[x][y-1]; if(board[x+1][y+1] != 0 && board[x+1][y] != ES) dboard[x+1][y+1] = board[x+1][y+1]; if(board[x+1][y-1] != 0 && board[x+1][y] != ES) dboard[x+1][y-1] = board[x+1][y-1]; if(board[x-1][y+1] != 0 && board[x+1][y] != ES) dboard[x-1][y+1] = board[x-1][y+1]; if(board[x-1][y-1] != 0 && board[x+1][y] != ES) dboard[x-1][y-1] = board[x-1][y-1]; solvearea(board, dboard, x, y); } if(board[x][y+1] == 0){ dboard[x][y++] = 0; if(board[x+1][y] != 0 && board[x+1][y] != ES) dboard[x+1][y] = board[x+1][y]; if(board[x-1][y] != 0 && board[x+1][y] != ES) dboard[x-1][y] = board[x-1][y]; if(board[x][y+1] != 0 && board[x+1][y] != ES) dboard[x][y+1] = board[x][y+1]; if(board[x][y-1] != 0 && board[x+1][y] != ES) dboard[x][y-1] = board[x][y-1]; if(board[x+1][y+1] != 0 && board[x+1][y] != ES) dboard[x+1][y+1] = board[x+1][y+1]; if(board[x+1][y-1] != 0 && board[x+1][y] != ES) dboard[x+1][y-1] = board[x+1][y-1]; if(board[x-1][y+1] != 0 && board[x+1][y] != ES) dboard[x-1][y+1] = board[x-1][y+1]; if(board[x-1][y-1] != 0 && board[x+1][y] != ES) dboard[x-1][y-1] = board[x-1][y-1]; solvearea(board, dboard, x, y); } if(board[x][y-1] == 0){ dboard[x][y--] = 0; if(board[x+1][y] != 0 && board[x+1][y] != ES) dboard[x+1][y] = board[x+1][y]; if(board[x-1][y] != 0 && board[x+1][y] != ES) dboard[x-1][y] = board[x-1][y]; if(board[x][y+1] != 0 && board[x+1][y] != ES) dboard[x][y+1] = board[x][y+1]; if(board[x][y-1] != 0 && board[x+1][y] != ES) dboard[x][y-1] = board[x][y-1]; if(board[x+1][y+1] != 0 && board[x+1][y] != ES) dboard[x+1][y+1] = board[x+1][y+1]; if(board[x+1][y-1] != 0 && board[x+1][y] != ES) dboard[x+1][y-1] = board[x+1][y-1]; if(board[x-1][y+1] != 0 && board[x+1][y] != ES) dboard[x-1][y+1] = board[x-1][y+1]; if(board[x-1][y-1] != 0 && board[x+1][y] != ES) dboard[x-1][y-1] = board[x-1][y-1]; solvearea(board, dboard, x, y); } if(board[x+1][y+1] == 0){ dboard[x++][y++] = 0; if(board[x+1][y] != 0 && board[x+1][y] != ES) dboard[x+1][y] = board[x+1][y]; if(board[x-1][y] != 0 && board[x+1][y] != ES) dboard[x-1][y] = board[x-1][y]; if(board[x][y+1] != 0 && board[x+1][y] != ES) dboard[x][y+1] = board[x][y+1]; if(board[x][y-1] != 0 && board[x+1][y] != ES) dboard[x][y-1] = board[x][y-1]; if(board[x+1][y+1] != 0 && board[x+1][y] != ES) dboard[x+1][y+1] = board[x+1][y+1]; if(board[x+1][y-1] != 0 && board[x+1][y] != ES) dboard[x+1][y-1] = board[x+1][y-1]; if(board[x-1][y+1] != 0 && board[x+1][y] != ES) dboard[x-1][y+1] = board[x-1][y+1]; if(board[x-1][y-1] != 0 && board[x+1][y] != ES) dboard[x-1][y-1] = board[x-1][y-1]; solvearea(board, dboard, x, y); } if(board[x+1][y-1] == 0){ dboard[x++][y--] = 0; if(board[x+1][y] != 0 && board[x+1][y] != ES) dboard[x+1][y] = board[x+1][y]; if(board[x-1][y] != 0 && board[x+1][y] != ES) dboard[x-1][y] = board[x-1][y]; if(board[x][y+1] != 0 && board[x+1][y] != ES) dboard[x][y+1] = board[x][y+1]; if(board[x][y-1] != 0 && board[x+1][y] != ES) dboard[x][y-1] = board[x][y-1]; if(board[x+1][y+1] != 0 && board[x+1][y] != ES) dboard[x+1][y+1] = board[x+1][y+1]; if(board[x+1][y-1] != 0 && board[x+1][y] != ES) dboard[x+1][y-1] = board[x+1][y-1]; if(board[x-1][y+1] != 0 && board[x+1][y] != ES) dboard[x-1][y+1] = board[x-1][y+1]; if(board[x-1][y-1] != 0 && board[x+1][y] != ES) dboard[x-1][y-1] = board[x-1][y-1]; solvearea(board, dboard, x, y); } if(board[x-1][y+1] == 0){ dboard[x--][y++] = 0; if(board[x+1][y] != 0 && board[x+1][y] != ES) dboard[x+1][y] = board[x+1][y]; if(board[x-1][y] != 0 && board[x+1][y] != ES) dboard[x-1][y] = board[x-1][y]; if(board[x][y+1] != 0 && board[x+1][y] != ES) dboard[x][y+1] = board[x][y+1]; if(board[x][y-1] != 0 && board[x+1][y] != ES) dboard[x][y-1] = board[x][y-1]; if(board[x+1][y+1] != 0 && board[x+1][y] != ES) dboard[x+1][y+1] = board[x+1][y+1]; if(board[x+1][y-1] != 0 && board[x+1][y] != ES) dboard[x+1][y-1] = board[x+1][y-1]; if(board[x-1][y+1] != 0 && board[x+1][y] != ES) dboard[x-1][y+1] = board[x-1][y+1]; if(board[x-1][y-1] != 0 && board[x+1][y] != ES) dboard[x-1][y-1] = board[x-1][y-1]; solvearea(board, dboard, x, y); } if(board[x-1][y-1] == 0){ dboard[x--][y--] = 0; if(board[x+1][y] != 0 && board[x+1][y] != ES) dboard[x+1][y] = board[x+1][y]; if(board[x-1][y] != 0 && board[x+1][y] != ES) dboard[x-1][y] = board[x-1][y]; if(board[x][y+1] != 0 && board[x+1][y] != ES) dboard[x][y+1] = board[x][y+1]; if(board[x][y-1] != 0 && board[x+1][y] != ES) dboard[x][y-1] = board[x][y-1]; if(board[x+1][y+1] != 0 && board[x+1][y] != ES) dboard[x+1][y+1] = board[x+1][y+1]; if(board[x+1][y-1] != 0 && board[x+1][y] != ES) dboard[x+1][y-1] = board[x+1][y-1]; if(board[x-1][y+1] != 0 && board[x+1][y] != ES) dboard[x-1][y+1] = board[x-1][y+1]; if(board[x-1][y-1] != 0 && board[x+1][y] != ES) dboard[x-1][y-1] = board[x-1][y-1]; solvearea(board, dboard, x, y); } } //error is here -> ../src/minesweeper.c:410: error: expected declaration or statement at end of input