C Tic Tac Toe not compiling

Enhance the tic-tac-toe game so 2 people can play. To do this, you need to add an“O” that, like the “X”, is drawn in the square. Then prompt the user for a square identifier, and alternate between drawing “X”s and “O”s at those locations on the board. The first move is for “X”. You need to detect and reject when a user plays a square that is already taken. Stop after the board is full (that is, 9 plays). You do not have to worry about who wins.
The “O” is to be 5 × 5, centered in the middle of the square.

Here are the messages your program should print to the standard output:

The tic-tac-toe board, with “X”s and “O”s as appropriate;
When it is “X”’s turn, print “X’s turn > ” (note the space after the “>”); and
When it is “O”’s turn, print “O’s turn > ” (again, note the space after the “>”).
Here are the error messages; all are to be printed on the standard error:

When the user enters only 1 co-ordinate: “Need 2 co-ordinatesn” (the ‘n’ is a newline);
When there is an illegal character in the input: “Illegal character in input “%c”n” (the “%c” is to print the offending character); and
When the square is already occupied: “%c has played %d,%dn” (where “%c” is either “X” or “O”, whichever is already in the square, and “%d,%d” are the co-ordinates of the occupied square); and
When an invalid set of co-ordinates are entered: “%d,%d” is not a valid square; the numbers must be between 1 and 3 inclusiven” (each %d is one of the invalid numbers).
If the program reads an end of file at the prompt, print a newline and quit.

The program should exit with an exit status code of 0.

  1. In problem 1, if the square is occupied, you need to give the error message. “%c has played %d,%dn” (where “%c” is either “X” or “O”, whichever is already in the square, and “%d,%d” are the co-ordinates of the occupied square).
  2. In problem 1, the dimensions of the “O” was added; it is to be 5 × 5 centered in the square.
  3. For all problems, the exit status code is 0.

If a blank line is input, exit without a message, just as if an EOF were typed.
On an error, don’t reprint the board, with one exception: if the uer enters the co-ordinates of a square that is occupied, reprint the board to refresh their memory of what squares are, and are not, available.

I tried the code at the bottom and it compiles everywhere else except for Gradescope which is where I need to submit this assignment. The error I get when I submit it is Test Failed: 1 != 0 : Compilation (gcc -ansi -pedantic -Wall -o /autograder/source/tests/ttt4a/ttt4a /autograder/submission/ttt4a.c ) failed and won’t compile. Please let me know what error was made!

#include <stdio.h>
#include <stdlib.h>

#define BOARD_SIZE 3

char board[BOARD_SIZE][BOARD_SIZE]; // The tic-tac-toe board

// Initialize the board with empty spaces
void initialize_board() {
    for (int i = 0; i < BOARD_SIZE; i++) {
        for (int j = 0; j < BOARD_SIZE; j++) {
            board[i][j] = ' ';
        }
    }
}

// Print the current state of the board
void print_board() {
    printf("n");
    printf("  1 2 3n");
    for (int i = 0; i < BOARD_SIZE; i++) {
        printf("%d ", i + 1);
        for (int j = 0; j < BOARD_SIZE; j++) {
            printf("%c", board[i][j]);
            if (j < BOARD_SIZE - 1) {
                printf("|");
            }
        }
        printf("n");
        if (i < BOARD_SIZE - 1) {
            printf("  -----n");
        }
    }
    printf("n");
}

// Check if the given player has won
int is_winner(char player) {
    // Check rows
    for (int i = 0; i < BOARD_SIZE; i++) {
        if (board[i][0] == player && board[i][1] == player && board[i][2] == player) {
            return 1;
        }
    }
    // Check columns
    for (int j = 0; j < BOARD_SIZE; j++) {
        if (board[0][j] == player && board[1][j] == player && board[2][j] == player) {
            return 1;
        }
    }
    // Check diagonals
    if ((board[0][0] == player && board[1][1] == player && board[2][2] == player) ||
        (board[0][2] == player && board[1][1] == player && board[2][0] == player)) {
        return 1;
    }
    return 0;
}

// Check if the board is full
int is_board_full() {
    for (int i = 0; i < BOARD_SIZE; i++) {
        for (int j = 0; j < BOARD_SIZE; j++) {
            if (board[i][j] == ' ') {
                return 0; // Board is not full
            }
        }
    }
    return 1; // Board is full
}

// Check if the given move is valid
int is_valid_move(int row, int col) {
    return row >= 0 && row < BOARD_SIZE && col >= 0 && col < BOARD_SIZE && board[row][col] == ' ';
}

// Make a move for the given player at the specified row and column
void make_move(char player, int row, int col) {
    board[row][col] = player;
}

int main() {
    initialize_board(); // Initialize the board
    char player = 'X'; // Player X starts the game
    int row, col;
    print_board(); // Print the initial board

    while (1) {
        if (player == 'X') {
            printf("X's turn > ");
        } else {
            printf("O's turn > ");
        }

        int result = scanf("%d,%d", &row, &col); // Read player's input
        if (result == EOF) {
            printf("n");
            return 0; // Exit gracefully on EOF
        } else if (result != 2) {
            fprintf(stderr, "Need 2 co-ordinatesn"); // Handle incorrect input format
            continue;
        }

        row--; // Adjusting to array indexing
        col--;

        if (!is_valid_move(row, col)) {
            fprintf(stderr, "%d,%d is not a valid square; the numbers must be between 1 and 3 inclusiven", row + 1, col + 1); // Handle invalid move
            continue;
        }

        if (board[row][col] != ' ') {
            fprintf(stderr, "%c has played %d,%dn", board[row][col], row + 1, col + 1); // Handle occupied square
            print_board(); // Reprint the board to refresh the memory
            continue;
        }

        make_move(player, row, col); // Make the move
        print_board(); // Print the updated board

        if (is_winner(player)) {
            printf("%c wins!n", player); // Check if the current player wins
            break;
        }

        if (is_board_full()) {`your text`
            printf("It's a tie!n"); // Check if the game is a tie
            break;
        }

        player = (player == 'X') ? 'O' : 'X'; // Switch player
    }

    return 0; // Exit successfully
}

New contributor

Marco Hernandez is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật