Mandarin
Mandarin

Reputation: 3

error: expected identifier or ‘(’ before ‘}’ token }

I know this question was already asked, and I checked all the previous answers but still cannot find the error. The program is not finished yet so the logic is incomplete, I just want to run and check what I have so far.

#include <math.h>
#include <stdio.h>
#include <omp.h>

int a[100][100];

int countNeighbors(int x, int y){

    int count = 0;
    int i,j;
    for (i = x-1; i <= x+1; i++)
        for (j = y-1; i <= y+1; j++)
            if (a[x][y] == 1) count++;

    return count;
}

int main (int argc, const char* argv[]) {

    int n, i, j, count;

    printf("Enter grid dimension:");
    scanf("%d",&n);   

// Initializing the array with random values
    srand (time(NULL));
    for (i=0;i<n;i++)
        for(j=0;j<n;j++)
            a[i][j] = rand() % 2;


    for (i=0;i<n;i++){
        printf("\n");
        for(j=0;j<n;j++)
            printf("%d",a[i][j]);
    }

    for (i = 1; i < n-1; i++)
        for (j = 1; j < n-1; j++){
            count = countNeighbors(i,j);
            if (a[i][j] == 1){
                if (count >= 4 || count <=1) a[i][j] = 0;
                else a[i][j] = 1;
            }   
            else if (count == 3) a[i][j] = 1;   
        }


    for (i=0;i<n;i++){
        printf("\n");
        for(j=0;j<n;j++)
            printf("%d",a[i][j]);
    }


}

Upvotes: 0

Views: 2540

Answers (1)

Random Davis
Random Davis

Reputation: 6857

It appears that the issue might be in the line #include <omp.h>. Some libraries may require you to include their header files in a certain order, or else they can result in errors like this. My suggestion is to try placing that #include at the top of the file. However, it does not appear that it is being used, so I would leave it out until you determine that you need it.

In addition, even if you remove that #include, you will need to make sure to #include <time.h> and #include <stdlib.h>, or else your calls to time() and rand() will result in compilation errors.

Upvotes: 1

Related Questions