Program Help

This is a discussion on Program Help within the C Programming forums, part of the General Programming Boards category; Hey all, im trying to write a program to create a small tic tac toe game (command line). im trying ...

  1. #1
    Registered User
    Join Date
    Nov 2010
    Posts
    8

    Question Program Help

    Hey all, im trying to write a program to create a small tic tac toe game (command line). im trying to make it using seperate functions for each process (such as to clear the board, or print the board). im fairly new to c and everytime i try to run my program i am given an output of a 3x3 matrix of /374/374/374 for every row. so far i am only trying to print a 3x3 matrix of all dashes.
    PS. i keep getting a warning saying" warning assignent makes integer from pointer without a cast". i have no idea what this means so if someone could explain it thatd be great.

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #define ROW 3
    #define COL 3
    #define TRUE 1
    #define FALSE 0
    
    
    void printboard (char b[ROW][COL]);
    void clearboard (char b[ROW][COL]);
    void play(char b[ROW][COL], char player);
    int checkwinner(char b [ROW][COL]);
    char testrow(char b[ROW][COL]);
    char testcols(char b[ROW][COL]);
    char testdiag(char b[ROW][COL]);
    int testdraw(char b[ROW][COL]);
    
    int main(){
    	char board[3][3];
    	clearboard(board);
    	printboard(board);
    	return 0;
    }
    
    void clearboard (char b[ROW][COL]){
    	int row, col;
    	for (row=0; row<3; ++row){
    		for (col=0; col<3; ++col){
    			b[row][col] = "-";
    		}
    	}
    
    }
    
    void printboard(char b[ROW][COL]){
    	int row, col;
    	for (row=0; row<3; ++row){
    		for (col=0; col<3; ++col){
    			printf ("%c",b[row][col]);
    		}
    		printf("\n");
    	}
    	
    }
    Output---
    \374\374\374
    \374\374\374
    \374\374\374

  2. #2
    Registered User claudiu's Avatar
    Join Date
    Feb 2010
    Location
    London, United Kingdom
    Posts
    2,094
    In your clear function you are assigning a single character b[row][col] a whole string "-". Assign '-' instead.
    1. Get rid of gets(). Never ever ever use it again. Replace it with fgets() and use that instead.
    2. Get rid of void main and replace it with int main(void) and return 0 at the end of the function.
    3. Get rid of conio.h and other antiquated DOS crap headers.
    4. Don't cast the return value of malloc, even if you always always always make sure that stdlib.h is included.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Issue with program that's calling a function and has a loop
    By tigerfansince84 in forum C++ Programming
    Replies: 9
    Last Post: 11-12-2008, 12:38 PM
  2. Need help with a program, theres something in it for you
    By engstudent363 in forum C Programming
    Replies: 1
    Last Post: 02-29-2008, 12:41 PM
  3. Replies: 4
    Last Post: 02-21-2008, 09:39 AM
  4. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21