Thread: misplaced )

  1. #1
    Registered User blight2c's Avatar
    Join Date
    Mar 2002
    Posts
    266

    misplaced )

    hey all, i'm getting those crazy erros that come with unbalanced brackets, but i can't find anything wrong. can u

    error:
    C:\mprog\atest\sor.cpp(55) : error C2146: syntax error : missing ')' before identifier 'card'
    C:\mprog\atest\sor.cpp(55) : error C2059: syntax error : ';'
    C:\mprog\atest\sor.cpp(55) : error C2059: syntax error : ')'
    C:\mprog\atest\sor.cpp(56) : error C2143: syntax error : missing ';' before '{'
    C:\mprog\atest\sor.cpp(102) : error C2146: syntax error : missing ')' before identifier 'i'
    C:\mprog\atest\sor.cpp(102) : error C2059: syntax error : ';'
    C:\mprog\atest\sor.cpp(102) : error C2059: syntax error : ')'
    C:\mprog\atest\sor.cpp(103) : error C2143: syntax error : missing ';' before '{'
    C:\mprog\atest\sor.cpp(103) : error C2143: syntax error : missing ')' before '++'
    C:\mprog\atest\sor.cpp(103) : error C2059: syntax error : ';'
    C:\mprog\atest\sor.cpp(103) : error C2059: syntax error : ')'
    C:\mprog\atest\sor.cpp(104) : error C2143: syntax error : missing ';' before '{'
    Error executing cl.exe.

    atest.exe - 12 error(s), 0 warning(s)

    Code:
    #include <iostream>
    #include <iomanip>
    #include <cstdlib>
    #include <ctime>
    #include <cstring>
    
    #define draw 5;
    
    using namespace std;
    
    
    void f_shuffle (int _deck [] [13]);
    void f_deal (int _hand [] [13], const int _deck [] [13]);
    void f_c_hand( const int _hand [] [13], const char *_face[], const char *_suit[] );
    void f_wins (const int _hand [] [13], const char *_face[], const char *_suit[]);
    void f_pair (char *face_card[]);
    
    main()
    {	const char *suit [4]={
    							"Hearts", "Diamonds", "Clubs", "Spades",};
    	const char *face [13]={
    							"Ace", "Deuce", "Three", "Four",
    							"Five", "Six", "Seven", "Eight",
    							"Nine", "Ten", "Jack", "Queen", "King",};
    	int deck [4] [13]={0};
    	int hand [4] [13]={0};
    	srand (time(0));
    
    	f_shuffle (deck);
    	f_deal (hand, deck);
    	f_c_hand(hand, face, suit);
    	f_wins (hand, face, suit);
    
    	return(0);
    }
    
    
    
    void f_shuffle (int _deck [] [13])
    {	int row, column;
    	for ( int card = 1; card <=52; card++)
    	{	do
    		{	row=rand() %4;
    			column=rand() %13;
    		}while (_deck [row] [column] !=0);
    		
    		_deck [row] [column] = card;
    	}
    }
    
    
    
    void f_deal (int _hand[][13], const int _deck [][13])
    {
    	for (int card=1; card<=draw; card++)
    	{	for (int row=0; row<=3; row++)
    		{	for (int column=0; column <=12; column++)
    			{	if (_deck [row] [column] == card)
    				{	_hand [row] [column] = 1;
    				}
    			}
    		}
    	}
    }
    
    
    
    void f_c_hand( const int _hand [] [13], const char *_face[], const char *_suit[] )
    {	cout<<"Your Hand: "<<endl<<endl;
    	for (int row=0; row<=3; row++)
    	{	for (int column=0; column <=12; column++)
    		{	if (_hand [row] [column] == 1)
    			{	cout<<setw(5)<<setiosflags(ios::right)
    					<<_face[column]
    					<<" of "<<_suit[row]<<endl;
    			}
    		}
    	}
    }
    
    
    void f_wins (const int _hand [] [13], const char *_face[], const char *_suit[])
    {	int counter=0; 
    	char *face_card [5]={"12345", "12345", "12345", "12345", "12345"};
    	char *suit_card [5]={"12345678", "12345678", "12345678", "12345678", "12345678"}; 
    	for (int column=0; column<13; column++)
    	{	for (int row=0; row<4; row++)
    		{	if (_hand [row] [column] ==1)
    			{	counter++;
    				strcpy(face_card[counter], _face[column]);
    				strcpy(suit_card[counter], _suit[row]);
    			}
    		}
    	}f_pair(face_card);
    	
    }
    
    
    
    void f_pair (char *face_card[])
    {
    	for (int i=0; i<draw; i++)
    	{	for (int j=i+1; j<draw-1; ++j)
    		{	if (strcmp(face_card[i], face_card[j])==0)
    			{	cout<<"you have a match"<<endl;
    				cout<<face_card[i]<<endl<<endl;
    			}
    		}
    	}
    }

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    The problem is way up at the top, here:
    #define draw 5;

    Take out the semicolon because everywhere you use draw, the preprocessor replaces it with 5;, not just 5. The for loops were choking on too many semicolons.

    -Prelude
    My best code is written with the delete key.

  3. #3
    Registered User
    Join Date
    Apr 2002
    Posts
    200
    <<#define draw 5; //define statements are not delimited with ;'s

    <<main() // argggggg int main() please-it returns 0

    when I change the define it compiles and runs fine on both mingw and borland 5.5 free cmdline. However, it won't compile as a C program.

    hope this helps
    I go to encounter for the millionth time the reality of experience and to forge in the smithy of my soul the uncreated conscience of my race.

    Windows XP consists of 32 bit extensions and a graphical shell for a 16 bit patch to an 8 bit operating system originally coded for a 4 bit microprocessor, written by a 2 bit company, that can't stand 1 bit of competition.

  4. #4
    Whats those commas doing there...


    "Hearts", "Diamonds", "Clubs", "Spades",}; //<---- get that last comma out


    "Ace", "Deuce", "Three", "Four", "Five", "Six", "Seven", "Eight",
    "Nine", "Ten", "Jack", "Queen", "King",}; //<---- get that last comma out


    Doesnt your compiler warn you about that? 'Too many initializers' or something...
    "There's always another way"
    -lightatdawn (lightatdawn.cprogramming.com)

  5. #5
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >Doesnt your compiler warn you about that? 'Too many initializers' or something...
    If I recall correctly, initialization lists for arrays will accept that last useless comma without warning or unusual after effects. Whether they are there or not doesn't matter, it's a fluke that evolved from C. I remember reading about that a long time ago, but I could be wrong.

    -Prelude
    My best code is written with the delete key.

  6. #6
    Registered User
    Join Date
    Apr 2002
    Posts
    200
    We was too late. (Anybody seen that old Python skit with the gangster/bishop?

    Priest: I baptise you in the name...*reaches for baptismal shellthingy*
    Bishop: *pulls up in a black sedan,brakes squealing,jumps out, wearing hat and staff and everything* Don't touch that!
    *huge explosion,priest dies*
    Bishop: We was too late.
    Oh no, God. Now I'm started quoting monty python! I'll never be able to stop now. Book of Armanents... there are those who call me tim...I fart in your general direction...the dead parrot...the ant shop...NOBODY EXPECTS THE SPANISH INQUISITION!!...
    Dear Lord, keep me away from that idiotic thread on the GD board, or else I'll be here for years. AAAAAAAGHHHHH...*convulses,writhes in agony*
    I go to encounter for the millionth time the reality of experience and to forge in the smithy of my soul the uncreated conscience of my race.

    Windows XP consists of 32 bit extensions and a graphical shell for a 16 bit patch to an 8 bit operating system originally coded for a 4 bit microprocessor, written by a 2 bit company, that can't stand 1 bit of competition.

  7. #7
    Registered User blight2c's Avatar
    Join Date
    Mar 2002
    Posts
    266
    hey guys, thanks a lot. it compiles fine but now crashes after "void f_c_hand . . " why does it stop? how can i make sense of the error report ms wants to send? again, thanks a lot here's the new source.

    Code:
    #include <iostream>
    #include <iomanip>
    #include <cstdlib>
    #include <ctime>
    #include <cstring>
    
    #define draw 5
    
    using namespace std;
    
    
    void f_shuffle (int _deck [] [13]);
    void f_deal (int _hand [] [13], const int _deck [] [13]);
    void f_c_hand( const int _hand [] [13], const char *_face[], const char *_suit[] );
    void f_wins (const int _hand [] [13], const char *_face[], const char *_suit[]);
    void f_pair (char *face_card[]);
    
    int main()
    {	const char *suit [4]={
    							"Hearts", "Diamonds", "Clubs", "Spades"};
    	const char *face [13]={
    							"Ace", "Deuce", "Three", "Four",
    							"Five", "Six", "Seven", "Eight",
    							"Nine", "Ten", "Jack", "Queen", "King"};
    	int deck [4] [13]={0};
    	int hand [4] [13]={0};
    	srand (time(0));
    
    	f_shuffle (deck);
    	f_deal (hand, deck);
    	f_c_hand(hand, face, suit);
    	f_wins (hand, face, suit);
    
    	return(0);
    }
    
    
    
    void f_shuffle (int _deck [] [13])
    {	int row, column;
    	for ( int card = 1; card <=52; card++)
    	{	do
    		{	row=rand() %4;
    			column=rand() %13;
    		}while(_deck [row] [column] != 0);
    		_deck [row] [column] = card;
    	}
    }
    
    
    
    void f_deal (int _hand[][13], const int _deck [][13])
    {	for (int card=1; card<=draw; card++)
    	{	for (int row=0; row<=3; row++)
    		{	for (int column=0; column <=12; column++)
    			{	if (_deck [row] [column] == card)
    				{	_hand [row] [column] = 1;
    				}
    			}
    		}
    	}
    }
    
    
    
    void f_c_hand( const int _hand [] [13], const char *_face[], const char *_suit[] )
    {	cout<<"Your Hand: "<<endl<<endl;
    	for (int row=0; row<=3; row++)
    	{	for (int column=0; column <=12; column++)
    		{	if (_hand [row] [column] == 1)
    			{	cout<<setw(5)<<setiosflags(ios::right)
    					<<_face[column]
    					<<" of "<<_suit[row]<<endl;
    			}
    		}
    	}
    }// somewhere around here it crashes 
    
    
    void f_wins (const int _hand [] [13], const char *_face[], const char *_suit[])
    {	int counter=0; 
    	char *face_card [5]={"12345", "12345", "12345", "12345", "12345"};
    	char *suit_card [5]={"12345678", "12345678", "12345678", "12345678", "12345678"}; 
    	for (int column=0; column<13; column++)
    	{	for (int row=0; row<4; row++)
    		{	if (_hand [row] [column] ==1)
    			{	counter++;
    				strcpy(face_card[counter], _face[column]);
    				strcpy(suit_card[counter], _suit[row]);
    			}
    		}
    	}f_pair(face_card);
    	
    }
    
    
    
    void f_pair (char *face_card[])
    {	for (int i=0; i<draw; i++)
    	{	for (int j=i+1; j<draw-1; ++j)
    		{	if (strcmp(face_card[i], face_card[j])==0)
    			{	cout<<"you have a match"<<endl;
    				cout<<face_card[i]<<endl<<endl;
    			}
    		}
    	}
    }

  8. #8
    Registered User blight2c's Avatar
    Join Date
    Mar 2002
    Posts
    266
    here's the "debug" report, but I haven't the faintest (is this asembly). the error occurs just after byte 3. and i think that corespondes to the strcpy in my function f_wins.

    ; main_loop_end:
    test dl,dl ; is it byte 0
    je short byte_0
    test dh,dh ; is it byte 1
    je short byte_1
    test edx,00ff0000h ; is it byte 2
    je short byte_2
    test edx,0ff000000h ; is it byte 3
    je short byte_3
    jmp short main_loop ; taken if bits 24-30 are clear and bit
    ; 31 is set
    byte_3:
    mov [edi],edx
    mov eax,[esp+8] ; return in eax pointer to dest string
    pop edi
    ret
    byte_2:
    mov [edi],dx
    mov eax,[esp+8] ; return in eax pointer to dest string
    mov byte ptr [edi+2],0
    pop edi
    ret

  9. #9
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >strcpy(face_card[counter], _face[column]);
    Big no-no, strcpy is trying to assign the contents of _face[column] to the read-only memory of face_card[counter], resulting in an access violation. If you want to easily change face_card[counter], make it a 2D array instead of an array of pointers. I should also mention that identifiers which start with an underscore are reserved by the implementation for further updates.

    -Prelude
    My best code is written with the delete key.

  10. #10
    Registered User
    Join Date
    Apr 2002
    Posts
    200
    just at a glance, I'd say the problem is that your arrays "suit" and "face" are arrays that contain pointers to string literals, but when you use them in f_c_hand, you are treating them just like regular arrays of type char. I'm not sure about it though, so I hope someone will correct me if I'm wrong.
    I go to encounter for the millionth time the reality of experience and to forge in the smithy of my soul the uncreated conscience of my race.

    Windows XP consists of 32 bit extensions and a graphical shell for a 16 bit patch to an 8 bit operating system originally coded for a 4 bit microprocessor, written by a 2 bit company, that can't stand 1 bit of competition.

Popular pages Recent additions subscribe to a feed