const char *p means the char value pointed by 'p' is constant we can't change anyway but the address(location) of 'p' can change.
char const *p means the char value pointed by 'p' can change but the location of p can't be change it is constant.
int printf (const char *fmt, ...)orint scanf (const char *fmt, ...)
in stdio.h:extern int printf (const char *fmt, ...);
// Tic-Tac-Toe // Plays the game of tic-tac-toe against a human opponent #include <iostream> #include <string> #include <vector> #include <algorithm> using namespace std; // global constants const char X = 'X'; const char O = 'O'; const char EMPTY = ' '; const char TIE = 'T'; const char NO_ONE = 'N'; // function prototypes void instructions(); char askYesNo(string question); int askNumber(string question, int high, int low = 0); char humanPiece(); char opponent (char piece); void displayBoard(const vector<char>& board); char winner(const vector<char>& board); bool isLegal(const vector<char>& board, int move); int humanMove (const vector<char>& board, char human); int computerMove(vector<char> board, char computer); void announceWinner (char winner, char computer, char human); // main function int main() { int move; const int NUM_SQUARES = 9; vector<char> board(NUM_SQUARES, EMPTY); instructions(); char human = humanPiece(); char computer = opponent(human); char turn = X; displayBoard(board); while (winner(board) human) { cout << winner << "'s won!\n"; cout << "No, no! It cannot be! Somehow you tricked me, human.\n"; cout << "But never again! I, the computer, so swear it!\n"; } else { cout << "It's a tie.\n"; cout << "You were most lucky, human, and somehow managed to tie me.\n"; cout << "Celebrate. . . for this is the best you will ever achieve.\n"; } }
You need to modify the argument type from char to const char: void fun (const char * Petr) {/*...*/}
char *strmerge (char *s3, const char *s1, const char *s2) { strcpy (s3, s1); strcat (s3, s2); return s3; }
// Tic-Tac-Toe // Plays the game of tic-tac-toe against a human opponent #include <iostream> #include <string> #include <vector> #include <algorithm> using namespace std; // global constants const char X = 'X'; const char O = 'O'; const char EMPTY = ' '; const char TIE = 'T'; const char NO_ONE = 'N'; void instructions(); char askYesNo(string question); int askNumber(string question, int high, int low = 0); char humanPiece(); char opponent(char piece); void displayBoard(const vector<char>* const pBoard); char winner(const vector<char>* const pBoard); bool isLegal(const vector<char>* const pBoard, int move); int humanMove(const vector<char>* const pBoard, char human); int computerMove(vector<char> board, char computer); void announceWinner(char winner, char computer, char human); // main function int main() { int move; const int NUM_SQUARES = 9; vector <char> board(NUM_SQUARES, EMPTY); instructions(); char human = humanPiece(); char computer = opponent(human); char turn = X; displayBoard(&board); while (winner(&board) human; board [move] = EMPTY; } if (!found) { ++move; } } } if (!found) { move = 0; unsigned int i=0; const int BEST_MOVES[] = {4, 0, 2, 6, 8, 1, 3, 5, 7}; while (!found && i< board.size()) { move = BEST_MOVES[i]; if (isLegal(move, &board)) { found = true; } ++i; } } cout << " I Shall take square number" << move << endl; return move; } void announceWinner(char winner, char computer, char human) { if (winner == computer) { cout << winner << "'s won!\n"; cout << "As I predicted, human, I am triumphant once more - proof\n"; cout << "that computers are superior to humans in all regards.\n"; } else if (winner == human) { cout << winner << "'s won!\n"; cout << "No, no! It cannot be! Somehow you tricked me, human.\n"; cout << "But never again! I, the computer, so swear it!\n"; } else { cout << "It's a tie.\n"; cout << "You were most lucky, human, and somehow managed to tie me.\n"; cout << "Celebrate... for this is the best you will ever achieve.\n"; } }
Everything. "inline" refers to functions, "const" refers to variables.
/* this is the same functionality as strcpy() */ /* note that this, like strcpy, is not buffer overrun safe */ char *StringCopy (char *destination, const char *source) { const char *temp = destination; while ((*destination++ = *source++) != '\0'); return temp; }
The spelling!
As usual, you should check official documentation before you ask a question like this. string.h // Copies num characters from source into destination. char* strncpy (char* destination, const char* source, size_t num); // Copies characters from source into destination. char* strcpy (char* destination, const char* source);
char* u_strcpy (char* dest, const char* src) { char* temp = dest; while ((*dest++ = *src++) != '\0'); return temp; }
char* strcpy(const char* src, char* dst) { char* tmp = dst; while ((*dst++ = *src++) != '\0'); return tmp; }