Thread: Weird (stupid?) Problem: error C2448: '<Unknown>'

  1. #1
    Dual
    Guest

    Weird (stupid?) Problem: error C2448: '<Unknown>'

    After a loong hitaeus from C++, due to other obligations, I decided to 'finish' my TicTacToe game; come to realize it was a complete mess I started again. I'll post the main function, that's what I belive to be causing the problem..


    Code:
    int main ()
    {
    	init();
    	table();
    	while (1)
    	{
    		if (moves <= 9)
    		{
    			if (checkWin(playerup) != 0 || checkWin(playerup) != 1)
    			{
    				getInput(playerup);
    				setInput(playerup);
    				SYSTEM("CLS");
    				playerup = 'o';
    			} else {
    				if (playerup == 'x')
    				{
    					cout << playername1 << " wins! Congratulations.";
    					table();
    					return 0;
    				} else {
    					cout << playername2 << "wins! Congratulations.";
    					table();
    					return 0;
    				}
    			}
    		} else {
    			cout << "No winner this time; thanks for playing!";
    			table();
    			return 0;
    		}
    
    	}
    	
    }
    And here are the errors:


    C:\My Documents\TicTacToe2\tictactoe.cpp(19) : error C2448: '<Unknown>' : function-style initializer appears to be a function definition
    C:\My Documents\TicTacToe2\tictactoe.cpp(19) : fatal error C1004: unexpected end of file found
    Error executing cl.exe.

    tictactoe.obj - 2 error(s), 0 warning(s)
    The first error points to the line where I initialize main, I can't figure out what I did wrong; although its probably something stupid. I assume the second error is derived from the first so that's not a worry..

  2. #2
    Unregistered
    Guest
    After adding in a few global vars, #include <iostream> and <cstdlib>, and setting up some stubbed functions, this program compiled fine for me on Dev-C++.

    My guess is that you typo'd one of your global vars or functions.


    Post the whole code?

  3. #3
    Dual
    Guest
    Code:
    #include <iostream.h>
    #include <windows.h>
    
    typedef unsigned short int USHORT;
    char board[3][3];
    char playername1[25];
    char playername2[25];
    char player1 = 'x';
    char player2 = 'o';
    char playerup = 'x';
    USHORT i, ii, iii, x, y, moves, move;
    
    void table(void);
    int init(void);
    int getInput(char player);
    int setInput(char player);
    USHORT checkWin(playerup)
    
    int main ()
    {
    	init();
    	table();
    	while (1)
    	{
    		if (moves <= 9)
    		{
    			if (checkWin(playerup) != 0 || checkWin(playerup) != 1)
    			{
    				getInput(playerup);
    				setInput(playerup);
    				SYSTEM("CLS");
    				playerup = 'o';
    			} else {
    				if (playerup == 'x')
    				{
    					cout << playername1 << " wins! Congratulations.";
    					table();
    					return 0;
    				} else {
    					cout << playername2 << "wins! Congratulations.";
    					table();
    					return 0;
    				}
    			}
    		} else {
    			cout << "No winner this time; thanks for playing!";
    			table();
    			return 0;
    		}
    
    	}
    	
    }
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    USHORT checkWin(playerup)
    {	
    	if (playerup == 'x')
    	{
    
    		if ((board[0][0] == board[0][1] && board[0][1] == board[0][2])
    		{
    
    			return 0;
    		}
    		if ((board[1][0] == board[1][1] && board[1][1] == board[1][2])
    		{
    
    			return 0;
    		}
    		if ((board[2][0] == board[2][1] && board[2][1] == board[2][2])
    		{
    
    			return 0;
    		}
    		//CHECK COLUMNS
    		if ((board[0][0] == board[1][0] && board[1][0] == board[2][0])
    		{
    
    			return 0;
    		}
    		if ((board[0][1] == board[1][1] && board[1][1] == board[2][1])
    		{
    
    			return 0;
    		}
    		if ((board[0][2] == board[1][2] && board[1][2] == board[2][2])
    		{
    
    			return 0;
    		}
    		//CHECK DIAGONALS
    		if ((board[0][2] == board[1][1] && board[1][1] == board[2][2])
    		{	
    
    			return 0;
    		}
    		if ((board[2][0] == board[1][1] && board[1][1] == board[0][2])
    		{	
    
    			return 0;
    		}
    
    
    	} else {
    
    
    		if ((board[0][0] == board[0][1] && board[0][1] == board[0][2])
    		{
    
    			return 1;
    		}
    		if ((board[1][0] == board[1][1] && board[1][1] == board[1][2])
    		{
    
    			return 1;
    		}
    		if ((board[2][0] == board[2][1] && board[2][1] == board[2][2])
    		{
    
    			return 1;
    		}
    		//CHECK COLUMNS
    		if ((board[0][0] == board[1][0] && board[1][0] == board[2][0])
    		{
    
    			return 1;
    		}
    		if ((board[0][1] == board[1][1] && board[1][1] == board[2][1])
    		{
    
    			return 1;
    		}
    		if ((board[0][2] == board[1][2] && board[1][2] == board[2][2])
    		{
    
    			return 1;
    		}
    		//CHECK DIAGONALS
    		if ((board[0][2] == board[1][1] && board[1][1] == board[2][2])
    		{	
    
    			return 1;
    		}
    		if ((board[2][0] == board[1][1] && board[1][1] == board[0][2])
    		{	
    
    			return 1;
    		}
    
    	}
    	return 2;
    	
    
    }
    
    void table(void)
    {
    	cout << "Current Table:\n";
    	cout << "+---+---+---+" <<endl;
    	cout << "| "<<board[0][0]<<" | "<<board[0][1]<<" | "<<board[0][2]<<" |" <<endl;
    	cout << "+---+---+---+" <<endl;
    	cout << "| "<<board[1][0]<<" | "<<board[1][1]<<" | "<<board[1][2]<<" |" <<endl;
    	cout << "+---+---+---+" <<endl;
    	cout << "| "<<board[2][0]<<" | "<<board[2][1]<<" | "<<board[2][2]<<" |" <<endl;
    	cout << "+---+---+---+" <<endl;
    }
    
    int init(void)
    {
    	cout << "Welcome to Tic Tac Toe\n";
    	cout << "Player 1, enter your name now->";
    	cin.getline(*playername1, 25, '\n');
    	cout << "\nPlayer 2; enter yours->";
    	cin.getline(*playername2, 25, '\n');
    
    	for (i = 0; i < 3; i++)
    	{
    		for (ii = 0; ii < 3; ii++)
    		{
    			for (iii = 1; iii<=9; iii++)
    			board[i][ii] = (char)iii;
    		}
    	}
    	return 0;
    }
    
    int getInput(char player)
    {
    	if (player == 'x')
    	{
    		cout << "Player 1, make your move->";
    		cin.getline(*move, 1, '\n');
    		switch (move)
    		{
    			case 1: { x = 0; y = 0; break; }
    			case 2: { x = 0; y = 1; break; }
    			case 3: { x = 0; y = 2; break; }
    			case 4: { x = 1; y = 0; break; }
    			case 5: { x = 1; y = 1; break; }
    			case 6: { x = 1; y = 2; break; }
    			case 7: { x = 2; y = 0; break; }
    			case 8: { x = 2; y = 1; break; }
    			case 9: { x = 2; y = 2; break; }
    			{
    				cout << "Invalid input, please restate->";
    				getInput(player);
    			}
    		}
    		return 1;
    	} else {
    		cout << "Player 2, make your move->";
    		cin.getline(*move, 1, '\n');
    		switch (move)
    		{
    			case 1: { x = 0; y = 0; break; }
    			case 2: { x = 0; y = 1; break; }
    			case 3: { x = 0; y = 2; break; }
    			case 4: { x = 1; y = 0; break; }
    			case 5: { x = 1; y = 1; break; }
    			case 6: { x = 1; y = 2; break; }
    			case 7: { x = 2; y = 0; break; }
    			case 8: { x = 2; y = 1; break; }
    			case 9: { x = 2; y = 2; break; }
    			{
    				cout << "Invalid input, please restate->";
    				getInput(player);
    			}
    		}
    		return 2;
    	}
    }
    
    int setInput(char player)
    {
    	if (board[x][y] != 'x' || board[x][y] != 'o')
    	{
    		board[x][y] = player;
    		moves++;
    		return 0;
    	} else {
    		cout << "That move has been made, try again";
    		getInput(playerup);
    	}
    }
    I tried a few things, its still not working..

  4. #4
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Location
    Hannover, Germany
    Posts
    3,130
    Your line: USHORT checkWin(playerup)

    Error: function-style initializer appears to be a function definition

    What is this ? A prototype ? Playerup needs a type. This line is missing a semicolon. The function implementation of it is missing the type, too.
    hth
    -nv

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Really Weird itoa Problem
    By Grantyt3 in forum C++ Programming
    Replies: 8
    Last Post: 12-20-2005, 12:44 AM
  2. stupid problem. answer = 0.0
    By spydrvnm in forum C Programming
    Replies: 6
    Last Post: 09-26-2004, 10:53 AM
  3. stupid problem in Dialog based Apps by MFC
    By AsAdi in forum Windows Programming
    Replies: 1
    Last Post: 02-06-2003, 01:47 PM
  4. I'm back (same stupid problem)
    By Zahl in forum C++ Programming
    Replies: 9
    Last Post: 10-22-2002, 10:29 AM
  5. A stupid chemistry problem
    By Shadow12345 in forum A Brief History of Cprogramming.com
    Replies: 10
    Last Post: 09-10-2002, 04:07 PM