I’m looking for help here. I know that the topic sound familiar, but I’ve looked in existing topic but couldn’t find a solution to my problem. I just beginning with C language and try to make this simple tic tac toe game with using of malloc but before I can even start to make mistakes I get error at the beginning. So there is mine main.c, game.h and game.c
main.c
#include <stdio.h>
#include <stdlib.h>
#include "game.h"
int main(int argc, char* argv[])
{
play_game();
return 0;
}
game.c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "game.h"
void play_game()
{
printf("Xs and Os!\n");
struct game *p_game_info = 0;
p_game_info = (struct game*)malloc(sizeof(struct game));
initialise_game (p_game_info, "John", "Annie");
draw_banner();
display_board(p_game_info->board);
}
void initialise_game(struct game* p_game_info, char* name1, char* name2)
{
p_game_info->status = P1_TURN;
for (int r=0; r<3; r++)
for(int c=0; c<3; c++)
p_game_info->board[r][c] = SPACE;
strncpy(p_game_info->playerNames[0], name1,MAX_NAME_LEN);
strncpy(p_game_info->playerNames[1], name2,MAX_NAME_LEN);
}
void draw_banner(){
printf("---------------\n");
printf(" GAME STATUS \n");
printf("---------------\n");
}
void display_board( char board[3][3]){
for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 3; j++)
{
printf("%c", board[i][j]);
if (j != 2)
printf("|");
}
if (i != 2)
printf("\n---------");
printf("\n");
}
}
game.h
#ifndef GAME_H_INCLUDED
#define GAME_H_INCLUDED
#define MAX_NAME_LEN 50
enum Bool { False, True };
enum status { P1_TURN, P2_TURN, P1_WON, P2_WON, DRAW };
typedef enum Bool boolean;
const char SPACE= '-';
const char X_SYMBOL = 'X';
const char O_SYMBOL = 'O';
struct game {
char board[3][3];
char playerNames[2][MAX_NAME_LEN];
int status;
boolean finished;
};
#endif
errors in function main.c multiple definition of 'X_SYMBOL' first defined here (points to void play_game(){) multiple definition of 'Y_SYMBOL' first defined here (points to void play_game(){) error:ld returned 1 exit status
Could anyone of you help me with that so I can go further and check if my code has any sense at all thanks