So I want to display an object with certain coordinates on the screen and make it able to move. If for example "u" is pressed it goes up and etc. So I tried using variables X and Y (initialized to 0) and after a "clear screen" deploying the object with a for loop. So check this out:
#include <iostream>
#include <conio.h>
#include <cstdlib>
#include <vector>
#include <iomanip>
using namespace std;
char input;
char player = 1;
char keyup = 0x48, keydown = 0x50, keyright = 0x4d, keyleft = 0x4b;
int x = 0, y = 0;
void position()
{
for (int start = 0; start <= y; start++)
{
cout << "\n";
}
for (int start = 0; start <= x; start++)
{
cout << " ";
}
cout << player;
}
void moveup()
{
x - 1;
system("cls");
position();
}
void movedown()
{
y + 1;
system("cls");
position();
}
void moveright()
{
x + 1;
system("cls");
position();
}
void moveleft()
{
y - 1;
system("cls");
position();
}
int main()
{
while (1)
{
position();
cin >> input;
if (input == keyup) moveup();
if (input == keydown) movedown();
if (input == keyright) moveright();
if (input == keyleft) moveleft();
system("cls");
}
}
So when I run it it just shows me the cube for ASCII key = 1; And no matter what I press it just blinks showing me the 'player' on the same position.
Can you guys tell me what is the PROBLEM?
At first, I recomment using character literals instead of numerical values:
char const keyup = 'u';
// ^ they are constants, aren't they???
0 is not a printable character, so using it as symbol won't print anything on the screen... You might use e. g. '+' instead.
Then you are repeating pretty much code within your functions. What you actually need is just one printing function; something like:
void update()
{
system("cls");
for(int i = 0; i < y; ++i)
std::cout << '\n'; // navigate to appropriate line
for(int i = 0; i < x; ++i)
std::cout << ' '; // navigate to column
std::cout << symbol << std::endl; // endl flashes buffer, too
}
You can use this to print the the symbol to current position (x/y). On input you just need to modify the coordinates (I personally recommend a switch statement instead of the if/else chain):
std::cin >> input;
switch(input)
{
case keyup: // NEEDS to be a constant to be used that way!
--y;
break;
case keydown:
++y;
break;
case keyleft:
--x;
break;
case keyright:
++x;
break;
default: // catch invalid user input
// if you have, appropriate error handling – or just ignore
break;
}
An empty default could be left out – it's a good habit, though, always to catch the invalid cases.
Finally: The second clearing of the screen (after your if/else chain) would empty the screen again before user might have seen anything. Just leave it out. All combined:
for(;;)
{
update(); // first screen update and returning here in every loop
std::cin >> input;
switch(input)
{
// ...
case ExitKey: // recommend to add it!
// the only disadvantage of switch: cannot use 'break' to exit loop!
goto LOOP_END;
default:
break;
}
}
LOOP_END:
// clean up application
return 0; // exit main...
One thing I yet omitted above, but very important: range checks! Before incrementing or decrementing one of the coordinates, you need to check if you can at all:
if(x > 0)
--x;
Or a variant I personally like:
y += y < SCREEN_HEIGHT; // needs to be defined appropriately...
About screen size: this might be of interest...
So the improved code would look like this:
#include <iostream>
#include <conio.h>
#include <cstdlib>
#include <vector>
#include <iomanip>
using namespace std;
char input;
char player = 1;
const char keyup = 'u', keydown = 'd', keyright = 'r', keyleft = 'l', Exitkey = 'k';
int x = 0, y = 0;
void space()
{
for (int start = 0; start < 7; start++)
{
cout << "\n";
}
}
void update()
{
system("cls");
for (int i = 0; i < y; ++i)
cout << '\n';
for (int i = 0; i < x; ++i)
cout << ' ';
cout << player << endl;
}
void inputfunc()
{
cin >> input;
switch (input)
{
case keyup:
if (y = 0)
{
y = 0;
}
else --y;
goto endloop;
case keydown:
++y;
goto endloop;
case keyleft:
if (x = 0)
{
x = 0;
}
else --x;
goto endloop;
case keyright:
++x;
goto endloop;
case Exitkey:
goto endloop;
default:
break;
}
endloop:;
}
int main()
{
for (;;)
{
update();
space();
inputfunc();
}
}
And one more thing: I do not know how to make it automatically after entering ONE character go on. I need to enter as many characters as I want and then press ENTER to deploy the player.How can I do that Scheff?
Related
Whenever I run my program I check to see if I would place down 3 os it goes to the right. I know that the problem is that I have a bunch of if statements that cycle through, but I have a for loop there to place down the snakes trail. I know that all those ifs aren't good.
I tried changing in the top of the for loop to be a if statement that was always true, it didn't work nothing did. I am confused on how to check for all of the coordinates, but still not have the walls pop up on the sides.
I am a begginer, so don't hate on my code that much.
snake.cpp
#include <iostream>
#include <conio.h>
#include <random>
#include <time.h>
#include "snake.hpp"
void endGame(int score);
const int KEY_ARROW_CHAR1 = 224;
const int KEY_ARROW_UP = 72;
const int KEY_ARROW_DOWN = 80;
const int KEY_ARROW_LEFT = 75;
const int KEY_ARROW_RIGHT = 77;
void snake::input() {
// checks for arrow key input
if (_kbhit()) {
//stores keycode
int key = _getch();
//checks if key is arrow key
if (key == KEY_ARROW_CHAR1) {
//stores arrow key
key = _getch();
//checks if arrow key is up
if (key == KEY_ARROW_UP) {
direction = '^';
}
//checks if arrow key is down
else if (key == KEY_ARROW_DOWN) {
direction = 'v';
}
//checks if arrow key is left
else if (key == KEY_ARROW_LEFT) {
direction = '<';
}
//checks if arrow key is right
else if(key == KEY_ARROW_RIGHT) {
direction = '>';
}
}
}
switch (direction) {
case '^':
snakeCoords[2]--;
break;
case 'v':
snakeCoords[2]++;
break;
case '>':
snakeCoords[0]++;
break;
case '<':
snakeCoords[0]--;
}
checkForObjects();
}
bool snake::checkForObjects() {
if ((snakeCoords[0] == 40 || snakeCoords[0] == 0) || (snakeCoords[2] == 20 || snakeCoords[2] == 0)) {
endGame(score);
}
if (snakeCoords[0] == fruitCoords[0] && snakeCoords[2] == fruitCoords[2]) {
score++;
getFruitLoc();
return true;
}
return false;
}
void snake::getFruitLoc() {
srand(time(0));
fruitCoords[0] = rand() % 39;
fruitCoords[2] = rand() % 19;
}
void endGame(int score) {
std::cout << "you died, your score was " << score;
exit(0);
}
```
#include <iostream>
#include <conio.h>
#include <random>
#include "snake.hpp"
#include <vector>
void createArena(char direction);
//Coordinates for snake
std::vector <std::vector<int>> previousCoords{
{14, 10},
{13, 10},
{12, 10}
};
snake coordManager{};
int score{0};
int main()
{
//make terminal green
system("color 0a");
while (true) {
std::cout << "\t" << score;
//pushes ascii arena down
for (size_t i{}; i <= 5; i++) {
std::cout << std::endl;
}
score = coordManager.score;
//updates snake based on coordinates
createArena(coordManager.direction);
//manages all snake movements
coordManager.input();
//reminder this clears the screan
system("CLS");
}
}
void createArena(char direction) {
//offsets screen
std::cout << "\t\t\t\t";
for (size_t y{}; y <= 20; y++) {
for (size_t x{}; x <= 40; x++) {
//checks if it hits the snakes coordinates
for (size_t i{}; i < previousCoords.size();) {
if (x == previousCoords.at(i).at(0) && y == previousCoords.at(i).at(1)) {
std::cout << "O";
}
i++;
}
if (coordManager.snakeCoords[0] == x && coordManager.snakeCoords[2] == y) {
std::cout << direction;
}
else if (x == 0 || x == 40) {
std::cout << '|';
}
else if (y == 0 || y == 20) {
std::cout << '-';
}
else if(coordManager.fruitCoords[0] == x && coordManager.fruitCoords[2] == y) {
std::cout << "F";
}
else {
std::cout << " ";
}
}
//offsets again
std::cout << std::endl << "\t\t\t\t";
}
}
#include <conio.h>
#include <random>
#include <time.h>
class snake {
public:
void input();
bool checkForObjects();
int score{};
int snakeCoords[2]{
/* X */ 15,
/* Y */ 10
};
int fruitCoords[2]{
/* X */ rand() % 39,
/* Y */ rand() % 19
};
char direction{'O'};
private:
void getFruitLoc();
};
https://i.stack.imgur.com/bdSNf.png
I got it working, I used a boolean that I would change if it was different from whitespace. it was a simple fix sorry.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 1 year ago.
Improve this question
This program runs a menu where the user is using keys. It runs as it is supposed to, but for some reason it returns a ridiculous value. I thought I messed up with breaks in the switch sequences, but nothing was wrong. I'm confused, because it prints out "All WHILE cycles passed" which means the next step is to return 0.
#include <iostream>
#include <windows.h>
#include <conio.h>
using namespace std;
#define KEY_UP 72
#define KEY_DOWN 80
#define ENTER_KEY 13
#define ESC_KEY 27
#define ERASE cout << " "
struct MENU
{
char text[50];
int id;
int color;
void menu_print(char* text)
{
cout << text << endl;
}
};
void set_color(int color);
void gotoxy(int x,int y);
int id_track(struct MENU *lines ,int amount_of_lines ,int x ,int ESCapable);
int main()
{
//setlocale(LC_ALL, "Russian");
int highlight = 13;
int highlight_warning = 12;
int highlight_accept = 10;
int _default = 7;
set_color(_default);
// Here "int highlight" is ASCII code for pink color. "int highlight_warning" and "int highlight_accept" are not used yet. "int _default" is ASCII code for white.
//######################################################################
MENU main_lines[2];
int main_amount = 3;
int main_escape = 0;
strcpy(main_lines[0].text,"1.Start work");
main_lines[0].id = 0;
main_lines[0].color = _default;
strcpy(main_lines[1].text, "2.Help");
main_lines[1].id = 1;
main_lines[1].color = _default;
strcpy(main_lines[2].text,"3.Quit");
main_lines[2].id = 2;
main_lines[2].color = _default;
// Lines user sees first
//######################################################################
struct MENU work_lines[4];
int work_amount = 5;
int work_escape = 1;
strcpy(work_lines[0].text,"#1.1 Action 1");
work_lines[0].id = 0;
work_lines[0].color = _default;
strcpy(work_lines[1].text, "#1.2 Action 2");
work_lines[1].id = 1;
work_lines[1].color = _default;
strcpy(work_lines[2].text,"#1.3 Action 3");
work_lines[2].id = 2;
work_lines[2].color = _default;
strcpy(work_lines[3].text,"#1.4 Action 4");
work_lines[3].id = 3;
work_lines[3].color = _default;
strcpy(work_lines[4].text,"#1.5 Action 5");
work_lines[4].id = 4;
work_lines[4].color = _default;
// Lines user will be able to interact after selecting the START WORK line
//#######################################################################
bool main_menu_active = true;
bool sub_menu_active;
while (main_menu_active)
{
switch(id_track(main_lines ,main_amount ,5 ,main_escape))
{
case 0:
main_menu_active = false;
sub_menu_active = true;
while(sub_menu_active)
{
switch(id_track(work_lines ,work_amount ,15 ,work_escape))
{
case 0:
gotoxy(50,2);
cout << "Work in process";
break;
case 1:
gotoxy(50,3);
cout << "Work in process";
break;
case 2:
gotoxy(50,4);
cout << "Work in process";
break;
case 3:
gotoxy(50,5);
cout << "Work in process";
break;
case 4:
gotoxy(50,6);
cout << "Work in process";
break;
case ESC_KEY:
sub_menu_active = false;
main_menu_active = true;
break;
default:
break;
}
}
break;
case 1:
gotoxy(15,3);
cout << "Help triggered";
break;
case 2:
main_menu_active = false;
break;
default:
break;
}
}
// Traces lines that user is able to select
cout << endl << "all WHILE cycles passed" << endl;
return 0;
}
void set_color(int color) //sets color - ASCII input value
{
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),color);
}
void gotoxy(int x,int y) //Sets cursor on asked position
{
COORD c;
c.X=x;
c.Y=y;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),c);
}
int id_track(struct MENU *lines ,int amount_of_lines ,int x ,int ESCapable)
{
int key_pressed;
int current_pos = 0;
bool RUN = true;
int i;
int highlight = 13;
int _default = 7;
amount_of_lines = amount_of_lines-1;
while (RUN)
{
key_pressed = 0;
for (i=0;i<=amount_of_lines;i++)
{
if (current_pos == ((lines+i) -> id))
{
set_color(highlight);
}
else
{
set_color(_default);
}
gotoxy(x,i+2);
(lines+i) -> menu_print((lines+i) -> text);
}
switch((key_pressed = getch()))
{
case KEY_UP:
if (current_pos < 0)
{
current_pos = 0;
}
if (current_pos > 0)
{
current_pos--;
}
break;
case KEY_DOWN:
if (current_pos > amount_of_lines)
{
current_pos = amount_of_lines;
}
if (current_pos < amount_of_lines)
{
current_pos++;
}
break;
case ESC_KEY:
if (ESCapable)
{
for (i=0;i<=amount_of_lines;i++)
{
gotoxy(x,i+2);
ERASE;
}
RUN = false;
return ESC_KEY;
break;
}
else
{
break;
}
case ENTER_KEY:
RUN = false;
set_color(_default);
return current_pos;
break;
default:
break;
}
}
}
Function returns on which line user pressed ENTER, variable ESCapable defines if user can press the ESC key to return to previous menu.
Here are the images of the program:
Working as it supposed to:
Cursed return value:
In C++, you have to specify the number of elements, not the maximum index, when declaring arrays.
Therefore, main_lines[2] for MENU main_lines[2]; and work_lines[4] for struct MENU work_lines[4]; are out-of-range, so you must not use them.
Allocate enough elements like MENU main_lines[3]; and struct MENU work_lines[5];.
I'm supposed to make a function that receives two arguments: a sentence(std::string) and bunch of phrases(std::vector<std::string>>). Now for all words in a sentence that are contained in the vector, I need to make their palindrome, and stick them together, e.g. compile -> compileelipmoc.
I also need to make sure that input is available up until two ENTER's are pressed.
The problem occurs after calling the function, where I seem to get stuck in an infinite loop.
Why am I getting this infinite loop?
#include <iostream>
#include <vector>
#include <string>
typedef std::vector<std::string> Vektor;
typedef std::string String;
void ReverseString(String &s1)
{
char temp(0);
for(int i(0); i < s1.size()/2; i++) {
temp = s1.at(i);
s1.at(i) = s1.at(s1.length()-1-i);
s1.at(s1.length()-1-i) = temp;
}
}
void CreatePalindrome(String s, Vektor v)
{
bool white_space(true);
bool go_on(false);
String compare;
for(int i(0); i < s.size(); i++) {
for(;;) {
if(s.at(i) == '\n' || i == s.size()-1) {
go_on == true;
break;
}
compare+=s.at(i);
}
if(go_on) {
for(int j(0); j < v.size(); j++) {
if(compare == v.at(j)) {
ReverseString(v.at(j));
if(i != s.size()-1) v.at(j)+=' ';
s.insert(i, v.at(j));
}
}
}
compare.clear();
}
}
int main ()
{
String sentence, phrase;
Vektor v1;
char character(0);
std::cout << "Enter your sentence: ";
std::getline(std::cin, sentence);
std::cout << "Enter phrases: ";
for(;;) {
character = std::cin.get();
if(character == '\n') break;
for(;;) {
phrase.push_back(character);
character = std::cin.get();
if(character == '\n') break;
}
v1.push_back(phrase);
phrase.clear();
}
CreatePalindrome(sentence, v1);
std::cout << "After the transformation, the sentence is: " << sentence;
return 0;
}
for(;;) {
if(s.at(i) == '\n' || i == s.size()-1) {
go_on == true;
break;
}
compare+=s.at(i);
}
Your only way out is via that if, but you modify neither s nor i in the loop, so you'll never break!
I've got a problem with creating an array of strings inside the object. I don't know how to patch it around so I'm asking for help. Here lies the problem:
main.h:
#pragma once
#include <iostream>
#include <conio.h>
#include <string>
class tab2D {
protected:
int width;
int height;
string **sTab;
int **iTab;
public:
tab2D();
tab2D(int x, int y, char c);
~tab2D();
tab2D(tab2D&t);
};
class chess: public tab2D {
public:
chess(int x, int y);
~chess();
chess(chess&c);
void init();
bool ifMove();
void show();
};
class matrix: public tab2D {
public:
matrix(int x, int y);
~matrix();
matrix(matrix&m);
};
The compiler says: syntax error : missing ';' before '*' about the line
string **sTab;
I assume that I can't make the dynamic array of strings and it makes further problems with processing this array.. Can you help me? :)
*UPDATE 1*Thanks, I forgot to add line
using namespace std;
Now it works, but I've got another problem.
#include "main.h"
using namespace std;
////// Konstruktor, konstruktor kopiujący oraz destruktor //////
chess::chess(int x = 8, int y = 8) : tab2D(x, y, 'c') {
init();
};
chess::chess(chess&c) {
chess(c.width, c.height);
};
chess::~chess() {
};
////// Metody //////
////// Uzupełnianie kolorów pól oraz rozstawianie figur i pionków //////
void chess::init() {
/// kolory pól: 0 - biały, 1 - czarny///
int last = 0;
for(int i = 0; i < this->height; ++i) {
for(int j=0; j < this->width; ++j) {
if(last = 0) {
this->sTab[i][j] = "1";
last = 1;
}
else if(last = 1) {
this->sTab[i][j] = "0";
last = 0;
}
}
if(last = 0)
last = 1;
else if(last = 1)
last = 0;
};
/// rozstawienie pionków ///
for(int i = 0; i < this->width; ++i) {
sTab[1][i] = sTab[1][i] + "0";
sTab[6][i] = sTab[6][i] + "a";
};
};
////// Wyświetlenie szachownicy //////
void chess::show() {
for(int i = 0; i < (this->height + 1); ++i) {
for(int j=0; j < (this->width + 1); ++j) {
if(i == 0 && j == 0)
cout << " ";
else if (i != 0 && j == 0) {
switch (i) {
case 1:
cout << "A ";
break;
case 2:
cout << "B ";
break;
case 3:
cout << "C ";
break;
case 4:
cout << "D ";
break;
case 5:
cout << "E ";
break;
case 6:
cout << "F ";
break;
case 7:
cout << "G ";
break;
case 8:
cout << "H ";
break;
default:
break;
}
}
else if (i == 0 && j != 0) {
cout << j << " ";
}
else {
cout << this->sTab[i-1][j-1] << " ";
}
}
cout << endl;
};
};
When I run the program, there is a breakpoint in the line
this->sTab[i][j] = "0";
I assume there is something wrong with making the array of strings but I don't understand why exactly there is a breakpoint and can't debug it.
UPDATE 2
Here is the code for tab.cpp:
#include "main.h"
using namespace std;
////// Konstruktor domyślny, konstruktor, konstruktor kopiujący oraz destruktor //////
tab2D::tab2D() {
};
tab2D::tab2D(int x, int y, char c) {
this->width = x;
this->height = y;
if (c == 'm') {
this->iTab = new int*[this->width];
for(int i=0;i<this->height;++i)
this->iTab[i] = new int[this->width];
}
else if (c == 'c') {
this->sTab = new string*[this->width];
for(int i=0;i<this->height;++i)
this->sTab[i] = new string[this->width];
}
else {
}
};
tab2D::tab2D(tab2D&t) {
tab2D(t.width, t.height, 't');
};
tab2D::~tab2D() {
for(int i=0;i<height;++i)
delete [] iTab[i];
delete [] iTab;
for(int i=0;i<height;++i)
delete [] sTab[i];
delete [] sTab;
};
You need to qualify names from the standard library:
std::string **sTab;
^^^^^
If you're doing what I think you're doing and allocating things with new, then you should consider using std::vector to deal with the quagmire of memory management issues you're about to encounter. If you really want to juggle pointers yourself for some reason, don't forget the Rule of Three.
UPDATE Your new problem might be because the copy constructor is horribly broken:
chess::chess(chess&c) {
chess(c.width, c.height);
};
This creates and destroys a temporary object, but doesn't initialise the object being constructed, leaving it in an invalid state. You probably don't want to declare a copy-constructor at all, as long as the base class is correctly copyable. If you did need one, it should should be more like:
chess::chess(chess const & c) : // 'const' so constant objects can be copied
tab2D(c) // copy the base-class subobject
{
// do whatever else needs doing
}
Alternatively, the new problem might be due to errors in the tab2D constuctors which you haven't shown us. The best way to track it down is to step through the program with a debugger, checking that everything is correctly initialised before use.
UPDATE Probably, the runtime error is caused by allocating the wrong number of pointers. You want
iTab = new int*[height]; // Not width
and likewise for sTab.
So I am trying to make a pretty basic TicTacToe in C++, and while I have no apparent syntax errors, I am having a lot of Debug errors of : "Unhandled exception at 0x0100142D in Cobra.exe: 0xC0000005: Access violation reading location 0xCCCCC359"
I feel like it is an obvious Error that I am just not processing but it;s definitely starting to grate my nerves. I'll label where the access error is... Right now it;s in my checkwin method but I feel like there is definitely more than one..
In my header I use a private char** board and a private int player.
#include "TicTacToe.h"
#include <iostream>
using namespace std;
int main()
{
int rowChosen,
colChosen;
TicTacToe newGame;
while(newGame.checkWin()==' ' && !newGame.fullBoard())
{
newGame.displayBoard();
do
{
cout << "Player " << newGame.getPlayer() << " choose a row and column.";
cin >> rowChosen >> colChosen;
newGame.setGame(rowChosen,colChosen);
}while(newGame.setGame(rowChosen,colChosen)==false);
newGame.makeMove(rowChosen, colChosen, newGame.getPlayer());
newGame.switchPlayer();
}
newGame.displayBoard();
if(newGame.checkWin()!=' ')
cout << "Player " << newGame.returnWinner() << " wins!";
else if(newGame.fullBoard()==true)
cout << "Cat's Game: This is a Draw!";
return 0;
}
TicTacToe::TicTacToe()
{
player = 1;
char blank = ' ';
for(int row=0;row<3;row++)
for(int col=0;col<3;col++)
board[row][col] = ' ';
}
void TicTacToe::setPlayer(int play)
{
player = play;
}
int TicTacToe::getPlayer()
{
return player;
}
void TicTacToe::switchPlayer()
{
if (player==1)
player++;
else
player--;
}
bool TicTacToe::setGame(int row, int col) //input validation
{
if (row >= 3 || row < 0)
return false;
if (col >= 3 || col < 0)
return false;
if (board[row][col] != ' ')
return false;
return true;
}
char TicTacToe::getBoard(int row, int col)
{
return board[row][col];
}
bool TicTacToe::fullBoard()
{
bool full = true;
for(int row=0;row<3;row++)
for(int col=0;col<3;col++)
{
if(board[row][col]==' ')
{
full=false;
break;
}
}
return full;
}
void TicTacToe::makeMove(int r, int c, int player)
{
char ch;
if (player==1)
ch = 'X';
else
ch = 'O';
board[r][c] = ch;
}
char TicTacToe::checkWin()
{
char b = ' ';
for(int i=0; i<3; i++) //horizontal
{
if((board[i][1]==board[i][0]) && (board[i][1]==board[i][2])) //THIS IS ERROR
{
b=board[i][1];
}
}
for(int j=0; j<3; j++) //vertical
{
if( (board[1][j]==board[0][j]) && (board[1][j]==board[2][j]) )
b=board[1][j];
}
if((board[0][0]==board[1][1] && board[1][1]==board[2][2]) ||
(board[2][0]==board[1][1] && board[1][1]==board[0][2]))
b= board[1][1];
return b;
}
void TicTacToe::displayBoard()
{
for(int row=0;row<3;row++)
{
cout << "|-----|";
for(int col=0;col<3;col++)
{
if(board[row][col]==' ')
cout << "| ";
else
cout << "|" << board [row][col];
}
cout << "|" << endl;
cout << "|-----|";
}
}
int TicTacToe::returnWinner()
{
int winner = 0;
if(checkWin()=='X')
winner = 1;
else if(checkWin()=='O')
winner = 2;
return winner;
}
This is my header TicTacToe.h
class TicTacToe
{
private:
char board[3][3]; //there we go
int player;
public:
TicTacToe();
void setPlayer(int);
int getPlayer();
void switchPlayer();
bool setGame(int,int);
char getBoard(int,int);
bool fullBoard();
void makeMove(int,int,int);
char checkWin();
void displayBoard();
int returnWinner();
};
Assuming you've included all the code, you're missing something essential: the declaration of the class TicTacToe. Of course, there's a TicTacToe.h, so it could be (probably is) hiding in there. That would help.
That all said, I think Mat has it right -- you declare a local named board inside the ctor and initialize it. But that goes out of scope as soon as the ctor is finished, which means all that initialization disappears into the aether.. Assuming you define board in your class, then simply removing that char declaration might be all you need.
Now, here's general advice: if you get an access violation exception, it usually means that you have made a mistake about the scope of something you're referring to. Since the exception happens at a point where you're using board, the slice of the program containing the identified board is the place to look.