[C++] Tic-Tac-Toe

I'm probably not doing this the best way possible. The code, to me, looks incredibly ugly and needs some optimization, but this is why I'm in the For Beginners section :-). Now, to move on past that... the issue I'm experiencing is weird. When I make my move, it will flash "Invalid move!" on the screen prompt; however, this doesn't display for more than half a second before a clearing of the screen takes place. This brings me to believe that my if-statement in the /* Program name: TicTacToe * Program author: Cameron Smith * Last updated: 6/2/2011 * Description: This is just a Tic-Tac-Toe clone created solely for educational purposes. It will follow the standard Tic-Tac-Toe rules . */ #include <iostream> #include <string> void drawGameBoard(char* gameBoard[3][3]); // function prototype void checkMove(char* gameBoard[3][3], int playerInput, int playerTurn); // another function prototype bool checkForWin(char* gameBoard[3][3]); int main() { // Introduction std::cout << "Welcome to Tic-Tac-Toe" << std::endl; std::cout << "Press ENTER to continue..." << std::endl; // Check for ENTER, then clear screen after pressing the key. std::cin.get(); system("cls"); char* gameBoard[3][3]; // The gameboard AMAGASH int playerInput = 0; // Used in the game loop to validate movement. int playerTurn = 1; // Used to determine to place an X or an O. gameBoard[0][0] = "1"; // top-left gameBoard[0][1] = "2"; // top-middle gameBoard[0][2] = "3"; // top-right gameBoard[1][0] = "4"; // middle-left gameBoard[1][1] = "5"; // middle-middle gameBoard[1][2] = "6"; // middle-right gameBoard[2][0] = "7"; // bottom-left gameBoard[2][1] = "8"; // bottom-middle gameBoard[2][2] = "9"; // bottom-right bool gameOver = false; while(gameOver != true) // The game loop :-). YAY! { drawGameBoard(gameBoard); std::cout << std::endl; std::cout << "Player " << playerTurn << ": Which spot would you like to take?

Char To String - News


Franny the Shopaholic: Buena reader looking for help spicing up her cider

•Big Lots has a stainless-steel three-burner Char-Broil gas grill on sale for $169. Homedics wrist blood-pressure monitor is $20. •The Christmas Tree Shop has Dad & Child grilling apron set for $9.99. Anti-gravity chairs are $39.99.



[C++] Tic-Tac-Toe

The single character is probably the newline left from the previous input. One option is to switch to a totally line based input system - use getline(std::istream &, std::string &) everywhere. You are doing pointer comparisons on char pointers in your



Strange SIGSEGV fault When calling D3DXCreateEffectFromFile Rate Content:

If I purposefully screw up the input filename string or don't make the file accessible it returns the proper invalid data error. All pointers involved have been initialised to NULL, once in the class constructor and once again in the function for good



SDL_net client-server problem

player*/) { //we receive data from any messages sent out to us string data = (char*)packets[n]->data; std::istringstream iss(data, istringstream::in); std::string tmp; iss >> tmp; //std::cout << player << " HANDLING PACKET " << tmp << endl;



Help understanding objects? (C++)

As for the "string object" vs "string literal" issue, that is a bit more technical. A string object is a chunk of data, usually an array of char values. A string literal like "abc" is a value you have typed in your code, it can be copied into objects.




c++ - Binary Data injected in String - Stack Overflow

Char s[256]; int num, fd; string command; command.


Twitter

Travis Woodward Nope, the code is fine, the reason is that string literals are c strings i.e. char*. C++ does char* to bool before char* to string


CSharp StackOverflow How to replace a char in string with an Empty character in C#.NET


Wabbit Loves Rangers Maybe if I just try to string together a bunch of 140 char thoughts I could get this done.


Brett Madsen is there a way to read in the length of a string to determine char length of column name for excel-going to TAB (MIPro can do it


all news 'Black Widow' Grandmother Dies Before Murder Trial: Woman, 79, whose five husbands ended up dead, had faced char...


Char To String - Bookshelf

The Java programming language

The Java programming language

9.6 Strings and char Arrays A String maps to an array of char and vice versa. You often want to build a string in a char array and then create a Stri ng ...

A Natural Introduction to Computer Programming with C#

A Natural Introduction to Computer Programming with C#

If no start position is given, the search starts from the last character position and proceeds towards the beginning of the string. ...

C++ and object-oriented numeric computing for scientists and engineers

C++ and object-oriented numeric computing for scientists and engineers

... //OK, assign a char to string } Notice that assigning a char to a string is allowed, although it is illegal to initialize a string by a char. ...

Computer algorithms, string pattern matching strategies

Computer algorithms, string pattern matching strategies

In a similar way, to match multiple patterns, if the character string[i] causes the current state .1 (not the start state) transit to the start state ...

Borland C++Builder 6 developer's guide

Borland C++Builder 6 developer's guide

Use a String Class Instead of char* Say goodbye to char* for string manipulation . ... For circumstances in which an old-style char* string is required, ...

Everyday Guide Directory


String (computer science) - Wikipedia, the free encyclopedia
Most string implementations are very similar to variable-length ... While character strings are very common uses of strings, a string in computer science may ...

C string - Wikipedia, the free encyclopedia
It is usually stored as one-dimensional character array.[dubious – discuss] The name refers to the C programming language which uses this string representation. ...

C Programming - Handling of character string
C Programming Handling of character string In this tutorial you will learn about Initializing Strings Reading Strings from the terminal Writing strings to screen ...

String: Definition from Answers.com
character string ( ′kariktər ′striŋ ) ( computer science ) A sequence of characters in a computer memory or other storage device

Character string data types
T-SQL character string and unicode character string datatypes are discussed in this book excerpt.
TOP