Expected init-declarator before "int"

I am here with a problem again. I am still working on my ticktacktoe game. I have tried everything i know to code that game again using arrays. At the end of the hard working i said "okay it will work fine this time." but the compiler give me that error. Here is my code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#include <iostream>
#include <string>
using namespace std;

int ticktacktoe( char alan[ ][ 3 ], string oyuncu, int tur )
int checker( char alan[ ][ 3 ], int x )
void hamle ( char alan[ ][ 3 ], char oyuncu , int x )


int main(){
    string oyuncu1;
    string oyuncu2;
    char birinci;
    char ikinci;
    char alan[ 3 ][ 3 ]
    
    int tur;
    int x;
    
    alan[ 0 ][ 0 ]='1';
    alan[ 0 ][ 1 ]='2';
    alan[ 0 ][ 2 ]='3';
    alan[ 1 ][ 0 ]='4';
    alan[ 1 ][ 1 ]='5';
    alan[ 1 ][ 2 ]='6';
    alan[ 2 ][ 0 ]='7';
    alan[ 2 ][ 1 ]='8';
    alan[ 2 ][ 2 ]='9';
    
    birinci = 'X';
    ikinci = 'O';
        
    cout<<"Birinci oyuncunun adini giriniz:";
    cin>>oyuncu1;
    
    cout<<"İkinci oyuncunun adini giriniz:";
    cin>>oyuncu2;
    
    while( tur <= 9 ){
    do    {cout<< oyuncu1 <<": X" << oyuncu2 << ": O";
          x=ticktacktoe( alan , oyuncu1, tur )
          } while(checker!=1);
    
    hamle( alan , birinci , x );
    ++tur;
    
    do    {cout<< oyuncu1 <<": X" << oyuncu2 << ": O";
          x=ticktacktoe( alan , oyuncu1, tur )
          } while(checker( alan , x )!=1);
    
    hamle( alan , birinci , x );
    ++tur;      
           
           }
     
    }
    
int tictacktoe( char alan[ ][ 3 ] , string oyuncu , int tur )
{int x;
            cout<<"____________\n";
            cout<<"| " << alan[ 0 ][ 0 ] << " | " << alan[ 0 ][ 1 ] << " | " << alan[ 0 ][ 2 ] <<" |\n";
            cout<<"|___|___|___|\n";
            cout<<"| " << alan[ 1 ][ 0 ] << " | " << alan[ 1 ][ 1 ] << " | " << alan[ 1 ][ 2 ] <<" |\n";
            cout<<"|___|___|___|\n";
            cout<<"| " << alan[ 2 ][ 0 ] << " | " << alan[ 2 ][ 1 ] << " | " << alan[ 2 ][ 2 ] <<" |\n";
            cout<<"|___|___|___|\n";
            cout<< oyuncu << ":";
            cin>>x;
            return x;
             
            
            }

int checker( char alan[ ][ 3 ] , int x)
{   if( x == 1 && alan[ 0 ][ 0 ] == '1'){return 1;}
    if( x == 2 && alan[ 0 ][ 1 ] == '2'){return 1;}
    if( x == 3 && alan[ 0 ][ 2 ] == '3'){return 1;}
    
    if( x == 4 && alan[ 1 ][ 0 ] == '4'){return 1;}
    if( x == 5 && alan[ 1 ][ 1 ] == '5'){return 1;}
    if( x == 6 && alan[ 1 ][ 2 ] == '6'){return 1;}
    
    if( x == 7 && alan[ 2 ][ 0 ] == '7'){return 1;}
    if( x == 8 && alan[ 2 ][ 1 ] == '8'){return 1;}
    if( x == 9 && alan[ 2 ][ 2 ] == '9'){return 1;}
    
    else {
         cout<< "Hatali giris yptiniz.";
         return 0;}
    
    }
    
void hamle( char alan[ ][ 3 ] , char oyuncu , int x )
{    if( x = 1) { alan[ 0 ][ 0 ] = oyuncu;}
     if( x = 2) { alan[ 0 ][ 1 ] = oyuncu;}
     if( x = 3) { alan[ 0 ][ 2 ] = oyuncu;}
     
     if( x = 4) { alan[ 1 ][ 0 ] = oyuncu;}
     if( x = 5) { alan[ 1 ][ 1 ] = oyuncu;}
     if( x = 6) { alan[ 1 ][ 2 ] = oyuncu;} 
     
     if( x = 7) { alan[ 2 ][ 0 ] = oyuncu;}
     if( x = 8) { alan[ 2 ][ 1 ] = oyuncu;}
     if( x = 9) { alan[ 2 ][ 2 ] = oyuncu;} 
       
     }


EDİT:okey i corrected that too. But there is a new error i didnt give me the line:

[Linker error] undefined reference to `ticktacktoe(char (*) [3], std::string, int)'
[Linker error] undefined reference to `ticktacktoe(char (*) [3], std::string, int)'
ld returned 1 exit status
Last edited on
It would be helpful if you told us which line of your code gives the compiler warning.

After all, if your compiler thinks it's helpful to tell you, don't you think it would be helpful to tell us?

In this case, the problem is right at the top of your code. The semicolon is missing from the ends of all three of your function declarations.

Edit: Line 15 is also missing a semicolon.
Last edited on
i marked line 6 as bold to show it is the line which compiler gives error but pardon me i will tell it next time.
thanks for your help
Oh, I didn't notice that! I don't think bold stands out very clearly in the code style on this forum, but thanks for giving it a try. Glad I was able to help :)
there was missing semi colons at line 41 and 45 i correct them but it gives a new error:

In function `int main()':
Line 42: ISO C++ forbids comparison between pointer and integer
okey i corrected that too. But there is a new error i didnt give me the line:

[Linker error] undefined reference to `ticktacktoe(char (*) [3], std::string, int)'
[Linker error] undefined reference to `ticktacktoe(char (*) [3], std::string, int)'
ld returned 1 exit status
checker is a function name that implicitly is converted to pointer to the function in expressions. You are trying to compare this pointer with integer literal 1. I think you meant a call of the function instead of using its name.

} while(checker!=1);
Last edited on
Checker is a function, so it needs to be called as one. Checker takes two arguments (int checker( char alan[ ][ 3 ], int x ), so when you call it you need to pass two arguments.
Checker is the name of a function, declared at line 6. The name of the function on its own is a function pointer, and you're trying to compare it to an integer value 1.

I assume what you actually intended to do was call the function?
I corrected it i was trying to call the function it was my fault but it gives a new error withot line:

[Linker error] undefined reference to `ticktacktoe(char (*) [3], std::string, int)'
[Linker error] undefined reference to `ticktacktoe(char (*) [3], std::string, int)'
ld returned 1 exit status
In the function definition try to retype the function name with all latin letters.

1
2
3
int tictacktoe( char alan[ ][ 3 ] , string oyuncu , int tur )
{int x;
...
Last edited on
thanks for help i compile the program it is not working fine but i can handle with it thanks again
it is the last code which works fine:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#include <iostream>
#include <string>
using namespace std;

int ticktacktoe( char alan[ ][ 3 ], string oyuncu, int tur );
int checker( char alan[ ][ 3 ], int x );
void hamle ( char alan[ ][ 3 ], char oyuncu , int x );


int main(){
    string oyuncu1;
    string oyuncu2;
    char birinci;
    char ikinci;
    char alan[ 3 ][ 3 ];
    
    int tur;
    int x;
    tur=1;
    
    alan[ 0 ][ 0 ]='1';
    alan[ 0 ][ 1 ]='2';
    alan[ 0 ][ 2 ]='3';
    alan[ 1 ][ 0 ]='4';
    alan[ 1 ][ 1 ]='5';
    alan[ 1 ][ 2 ]='6';
    alan[ 2 ][ 0 ]='7';
    alan[ 2 ][ 1 ]='8';
    alan[ 2 ][ 2 ]='9';
    
    birinci = 'X';
    ikinci = 'O';
        
    cout<<"Birinci oyuncunun adini giriniz:";
    cin>>oyuncu1;
    
    cout<<"Ikinci oyuncunun adini giriniz:";
    cin>>oyuncu2;
    
    while( tur <= 9 ){
    do    {cout<< oyuncu1 <<": X" << oyuncu2 << ": O\n";
          x=ticktacktoe( alan , oyuncu1, tur );
          } while(checker( alan , x )!=1);
    
    hamle( alan , birinci , x );
    ++tur;
    
    do    {cout<< oyuncu1 <<": X" << oyuncu2 << ": O\n";
          x=ticktacktoe( alan , oyuncu2, tur );
          } while(checker( alan , x )!=1);
    
    hamle( alan , ikinci , x );
    ++tur;      
           
           }
     
    }
    
int ticktacktoe( char alan[ ][ 3 ] , string oyuncu , int tur )
{int x;
            cout<<" ___________\n";
            cout<<"| " << alan[ 0 ][ 0 ] << " | " << alan[ 0 ][ 1 ] << " | " << alan[ 0 ][ 2 ] <<" |\n";
            cout<<"|___|___|___|\n";
            cout<<"| " << alan[ 1 ][ 0 ] << " | " << alan[ 1 ][ 1 ] << " | " << alan[ 1 ][ 2 ] <<" |\n";
            cout<<"|___|___|___|\n";
            cout<<"| " << alan[ 2 ][ 0 ] << " | " << alan[ 2 ][ 1 ] << " | " << alan[ 2 ][ 2 ] <<" |\n";
            cout<<"|___|___|___|\n";
            cout<< oyuncu << ":";
            cin>>x;
            return x;
             
            
            }

int checker( char alan[ ][ 3 ] , int x)
{   if( x == 1 && alan[ 0 ][ 0 ] == '1'){return 1;}
    if( x == 2 && alan[ 0 ][ 1 ] == '2'){return 1;}
    if( x == 3 && alan[ 0 ][ 2 ] == '3'){return 1;}
    
    if( x == 4 && alan[ 1 ][ 0 ] == '4'){return 1;}
    if( x == 5 && alan[ 1 ][ 1 ] == '5'){return 1;}
    if( x == 6 && alan[ 1 ][ 2 ] == '6'){return 1;}
    
    if( x == 7 && alan[ 2 ][ 0 ] == '7'){return 1;}
    if( x == 8 && alan[ 2 ][ 1 ] == '8'){return 1;}
    if( x == 9 && alan[ 2 ][ 2 ] == '9'){return 1;}
    
    else {
         cout<< "Hatali giris yptiniz.";
         return 0;}
    
    }
    
void hamle( char alan[ ][ 3 ] , char oyuncu , int x )
{   if( x == 1) { alan[ 0 ][ 0 ] = oyuncu;}
     if( x == 2) { alan[ 0 ][ 1 ] = oyuncu;}
     if( x == 3) { alan[ 0 ][ 2 ] = oyuncu;}
     
     if( x == 4) { alan[ 1 ][ 0 ] = oyuncu;}
     if( x == 5) { alan[ 1 ][ 1 ] = oyuncu;}
     if( x == 6) { alan[ 1 ][ 2 ] = oyuncu;} 
     
     if( x == 7) { alan[ 2 ][ 0 ] = oyuncu;}
     if( x == 8) { alan[ 2 ][ 1 ] = oyuncu;}
     if( x == 9) { alan[ 2 ][ 2 ] = oyuncu;} 
       
     }


note: I marked as bold where i corrected
Topic archived. No new replies allowed.