ggbet121
ggbet121

Reputation: 19

'%s' expects argument of type 'char *', but argument has type 'int'

I did see a similar question and the solution given was to declare it as char array and not a char. I did that and still see the error.

My code is currently this :

#include <stdio.h>
char ticTacToeBoard(char board[11])

{
    printf("%s %s %s %s %s", board[0], board[10], board[1], board[10], board[2]);
}


int main()

{
    char board[11] = {' ',' ',' ',' ',' ',' ',' ',' ',' ','__','|'};
    ticTacToeBoard(board);

    return 0;
}

The error is in the printf line of the code

Upvotes: 0

Views: 1161

Answers (1)

Gilad
Gilad

Reputation: 305

the function parameter board is a char pointer, so when you try to print an index of that char pointer it gives the dereference of the char in that index. so what happens is you try to print a string but the variable is a char. if you want to print the char you'll need the to change the %s to a %c. this way you'll print the chars you want from the indexes in the "array" of chars.

Upvotes: 1

Related Questions