Skip to main content

Create Simple Tic Tac Toe Game In Pure C Language.

Hello Friends,

Welcome Again To My Blog. Today, In This Post I am going to share another Example Script of Simple Game Tic Tac Toe Written in Pure C Language. Well, Actually I wrote this script just for Fun and interesting point is This, In This Script I Tried To Wrote In Minimum But Readable Way. I'm hoping that if you are new in C Programming And Wondering How We Can Play With C programming than This Script Going To Give You Good Taste Of C Programming.

System Requirements.

Nothing, That Much Just A C Compiler. Here, I Used GCC.

How it's working

Well I Used An Array List To Keep Record Of Game Status And Few If And Else Conditions To Find Game Status. Simple, Like A Piece Of Cake Nothing Difficult To Understand.

Here Are My Code.

Tic Tac Toe Game In C

Author  : Suraj Singh Bisht
Email   :
Description : Trying To Write, Tic Tac Toe Game In Minimum Lines
Compile Command : gcc ExampleScript.c -o a.out && ./a.out 

// Include modules
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>


// array to keep remember
char s[9] = {'.','.','.','.','.','.','.','.','.'};
int turn=0;

// 0 1 2
// 3 4 5
// 6 7 8

// game status
int status(char p){
 // complete rail of conditions
 if ((s[0]==s[1] && s[1]==s[2] && s[0]==p)||(s[3]==s[4] && s[4]==s[5] &&\
  s[5]==p)||(s[6]==s[7] && s[7]==s[8] && s[8]==p)||(s[0]==s[3] && \
  s[3]==s[6] && s[6]==p)||(s[1]==s[4] && s[4]==s[7] && s[7]==p)||(s[2]==s[5]\
  && s[5]==s[8] && s[8]==p)||(s[0]==s[4] && s[4]==s[8] && s[8]==p)||(s[6]==s[4]\
  && s[4]==s[2] && s[2]==p)){
  return 1;
 return 0;


// display board function
void displayboard(void){
 // clear display
 // print board
 printf("\n\n %c | %c | %c ---->   0 | 1 | 2 \n-------------\n %c | %c | %c ---->   3 | 4 | 5 \n-------------\n %c | %c | %c ---->   6 | 7 | 8  \n\n\n", s[0],s[1],s[2],s[3],s[4],s[5],s[6],s[7],s[8]);

// check array input
int checkinput(int i){
 if (i<9){
   return 1;}
  return 0;
 };return 0;

// Players Turn
int player(char p){
 int ret=0;
 // show display
 // Input value space
 int i;
 // print about player
 printf("[+] Player [%c] This is Your Turn\n[+] Now Insert Your New Mark Index Number : ", p);
  // scan variable
  scanf("%d", &i);
 }while( !isdigit(i) && !checkinput(i) );
 // Insert mark
 turn += 1;
  printf("[-] Game Tie.\n");
  printf("!!Winner!!, Player [%c] is winner.\n", p); 
        // print va variable
        printf("[+] Player [%c], Your Index Accepted : %d , Turn No. %d",p, i, turn);
 // return value
 return ret;

// Trigger
int main(){
 // Display Status
 // while loop
  // first player turn
  // second player turn

To Compile Codes In Linux, Type In Terminal
gcc path_to_source_code -o output_file_name



Related Post

Top Visited

Create Simple Packet Sniffer Using Python

how to install burp suite in Linux/Ubuntu 16.04

List of Keyboard Shortcuts Keys for GNOME Desktop (Kali linux / Linux / Ubuntu/*nix )

How to create Phishing Page Using Kali Linux | Webpage Page Cloning Using Kali Linux Social Engineering Toolkit

Best 1000 User-agents List For Web Scraping

Big List Of Google Dorks For Sqli Injection

How To Install GDB Peda?

Latest Google Dorks List

How To Create Snake Game Using Python And Tkinter - Simple python games

2 Easiest Way To Enable Monitor Mode in Kali Linux | Airmon-ng | Iwconfig