Tic Tac Toe Code in C Programming with Source Code

The Tic Tac Toe Code In C Programming is developed using C programming language. This game is played on a 3×3 grid by two players.

A tic tac toe game c program first player uses a circle to mark his movements, while the second uses a cross. The tic tac toe using c player who has made a three-mark horizontal, vertical, or diagonal series wins.

Additionally, both players must enter a particular number one to nine based on the grid position in order to make a mark X or O.

About The Project

The tic tac toe program in c 3×3 winner will be the first player to successfully position three of their marks in a horizontal, vertical, or diagonal) row.

This Console Application also includes a downloadable code for tic tac toe in c for free, just find the downloadable source code below and click to start downloading.

To run this tic tac toe program in c with output make sure that you have a Code Blocks or any platform of C++ installed in your computer.

Tic Tac Toe In C Programming Project Details

ABOUT PROJECTPROJECT DETAILS
Project Name :tic tac toe algorithm
Project Platform :C/C++
Programming Language Used:C Programming Language
Developer Name :itsourcecode.com
IDE Tool (Recommended):Dev-C++/Codeblocks
Project Type :Desktop Application
Database:Stores data in .DAT file
Tic Tac Toe In C Programming With Source Code Information

Tic Tac Toe In C Programming With Source Code Steps On How To Run The Project

Time needed: 5 minutes

These are the steps on how to run Tic Tac Toe In C Programming With Source Code

  • Step 1: Download

    First, download the source code given below.

    Tic-Tac-Toe-Game-In-C-Step-1

  • Step 2: Extract file.

    Second, after you finished download the source code, extract the zip file.
    Tic-Tac-Toe-Game-In-C-Step-2

  • Step 3: Open CodeBlocks

    Third, open “CodeBlocks IDE”.

  • Step 4: Open Project.

    Fourth, open file tab and Open File after that open folder TicTacToeC then click the “tictactoec.c“.

  • Step 5: Run Project

    Fifth, run the project.

  • Step 6: The actual code.

    You are free to copy the given source code below or download the downloadable source code given.

The Code Given Below is the Actual Code of System

#include <stdio.h>
#include <conio.h>

char square[10] = { 'o', '1', '2', '3', '4', '5', '6', '7', '8', '9' };

int checkwin();
void board();

int main()
{
    int player = 1, i, choice;

    char mark;
    do
    {
        board();
        player = (player % 2) ? 1 : 2;

        printf("   Player %d, enter a number:  ", player);
        scanf("%d", &choice);

        mark = (player == 1) ? 'X' : 'O';

        if (choice == 1 && square[1] == '1')
            square[1] = mark;

        else if (choice == 2 && square[2] == '2')
            square[2] = mark;

        else if (choice == 3 && square[3] == '3')
            square[3] = mark;

        else if (choice == 4 && square[4] == '4')
            square[4] = mark;

        else if (choice == 5 && square[5] == '5')
            square[5] = mark;

        else if (choice == 6 && square[6] == '6')
            square[6] = mark;

        else if (choice == 7 && square[7] == '7')
            square[7] = mark;

        else if (choice == 8 && square[8] == '8')
            square[8] = mark;

        else if (choice == 9 && square[9] == '9')
            square[9] = mark;

        else
        {
            printf("   Invalid move ");

            player--;
            getch();
        }
        i = checkwin();

        player++;
    }while (i ==  - 1);

    board();

    if (i == 1)
        printf("   ==>\aPlayer %d win ", --player);
    else
        printf("   ==>\aGame draw");

    getch();

    return 0;
}

int checkwin()
{
    if (square[1] == square[2] && square[2] == square[3])
        return 1;

    else if (square[4] == square[5] && square[5] == square[6])
        return 1;

    else if (square[7] == square[8] && square[8] == square[9])
        return 1;

    else if (square[1] == square[4] && square[4] == square[7])
        return 1;

    else if (square[2] == square[5] && square[5] == square[8])
        return 1;

    else if (square[3] == square[6] && square[6] == square[9])
        return 1;

    else if (square[1] == square[5] && square[5] == square[9])
        return 1;

    else if (square[3] == square[5] && square[5] == square[7])
        return 1;

    else if (square[1] != '1' && square[2] != '2' && square[3] != '3' &&
        square[4] != '4' && square[5] != '5' && square[6] != '6' && square[7]
        != '7' && square[8] != '8' && square[9] != '9')

        return 0;
    else
        return  - 1;
}


/*******************************************************************
FUNCTION TO DRAW BOARD OF TIC TAC TOE WITH PLAYERS MARK
 ********************************************************************/


void board()
{
    system("cls");
    printf("\n\n   \xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\n");
    printf("\t   Tic Tac Toe");
    printf("\n   \xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\n\n");

    printf("   Player 1 (X)  -  Player 2 (O)\n\n");


    printf("   \xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\n");
    printf("\t|     |     |     |\n");
    printf("\t|  %c  |  %c  |  %c  |\n", square[1], square[2], square[3]);

    printf("\t|_____|_____|_____|\n");
    printf("\t|     |     |     |\n");

    printf("\t|  %c  |  %c  |  %c  |\n", square[4], square[5], square[6]);

    printf("\t|_____|_____|_____|\n");
    printf("\t|     |     |     |\n");

    printf("\t|  %c  |  %c  |  %c  |\n", square[7], square[8], square[9]);

    printf("\t|     |     |     |\n");
    printf("   \xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\n\n");
}

Downloadable Source Code

Conclusion

This tic tac toe algorithm in c is only a project made for school requirement purposes only. You can download this source code and modify it to suit your client requirements, since this is a student project it means you cannot really expect 100% functionality from this.

Frequently Asked Questions

How does this C / C++ game project work?

Built with C or C++ console I/O (printf/cout, scanf/cin, getch from conio.h). Game state in arrays or structs, game loop via while(running). Input via _kbhit() + _getch() (Windows) or termios (Linux). Common starter games: Snake, Tic-Tac-Toe, Hangman, Tetris, Chess. Foundation BSIT 1st-2nd year mini-project.

What compiler do I need to run this C or C++ project?

For C: gcc (GNU Compiler Collection) or MinGW (Windows). For C++: g++. IDE options: Code::Blocks (lightweight, built-in compiler), Dev-C++ (classic Philippine BSIT favorite), Visual Studio Code with C/C++ extension, CLion (paid). To compile from terminal: gcc program.c -o program (for C) or g++ program.cpp -o program (for C++), then run with ./program (Linux/macOS) or program.exe (Windows).

How do I run this C / C++ project?

Open the .c or .cpp file in your IDE (Code::Blocks, Dev-C++, VS Code). Click Build (or press F9), then Run (or press F5). From terminal: navigate to project folder, run gcc/g++ command above, then ./program. If using file storage, make sure the data file (e.g. records.txt) is in the same folder as the executable.

Can I use this C / C++ project for a BSIT capstone or thesis?

C/C++ projects are usually accepted for 1st-2nd year mini-projects or as building blocks. For a full capstone you would typically pair them with a more interactive frontend (e.g. wrap C++ logic with a Java/Python/PHP frontend, or extend to GTK/Qt for a real GUI). Standalone console C++ capstones are accepted by some panels but rare in 2026.

Why am I getting ‘undeclared identifier’ or ‘cannot find header’ errors?

Three common C/C++ issues: (1) Missing #include directive, e.g. #include for printf, #include for strcpy. (2) conio.h is Windows-only (Borland/MinGW), not POSIX, use ncurses on Linux/macOS. (3) Linker error: function declared but not defined, ensure all source files are in the compile command (gcc main.c utils.c -o app) or use a Makefile.

Where can I find more C or C++ projects with source code?

Browse the C and C++ Projects hub for the full library. For Java desktop alternatives see Java Projects. For higher-level languages see Python Projects. For BSIT capstone idea lists see 150 Best Capstone Project Ideas.

Leave a Comment