C program character array error

时间:2018-03-25 19:04:37

标签: c arrays char

So I'm fairly new to the concept of arrays and very new to the concept of functions. Right now I am trying to create a 3 x 3 array with all "_" that can later be modified with other functions. This is the code that I have so far:

#include<stdio.h>
#define SIZE 3



void clear_table(char ary[SIZE][SIZE])
{

    for(int i = 0; i < SIZE; i++)

    {
        for( int j = 0; j < SIZE; j++)
        {
            ary[i][j] = "_";
        }

    }



}

void display_table(char ary[SIZE][SIZE])
{
for( int i = 0; i < SIZE; i++)
{
    for( int j = 0; j < SIZE; j++)
    {
        printf("%c", ary[i][j]);
    }
    printf("\n");
}

}

int main ()
{
   //Declare the tic-tac-toe board
   char board[SIZE][SIZE];
   //The row and column of the move for either player 1 or 2
   int row, col;
   //Clear the table
   clear_table(board);
   //Display the table
   display_table(board);

   return 0;
}

But I get an error with this code:

warning: assignment makes integer from pointer without a cast [-Wint-conversion]
    ary[i][j] = "_";

And when I execute the program I get:

$$$
$$$
$$$

Instead of:

_ _ _
_ _ _ 
_ _ _ 

Can someone help me make sense of this error?

1 个答案:

答案 0 :(得分:0)

On line 14, you are using ary[i][j] = "_";

Use ary[i][j] = '_'; instead.

Initially, you are assigning a string, whereas you want a character