strcpy() showing incompatible integer to pointer conversion

67 views Asked by At
    char arr[3][3] = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};
    char var;

    // Asking input from user
    for (int l = 0; l < 3; l++)
    {
        for (int k = 1; k < 3; k++)
        {
            if (k % 2 != 0)
            {
                var = get_int("Enter position for x: ");
                strcpy(arr[l][k], "x");
            }
            else
            {
                var = get_int("Enter position for o: ");
                strcpy(arr[l][k], "o");
            }
            design(var, arr);
        }
    }
arrays/ $ make tictactoe
tictactoe.c:20:24: error: incompatible integer to pointer conversion passing 'char' to parameter of type 'char *'; take the address with & [-Werror,-Wint-conversion]
                strcpy(arr[l][k], "x");
                       ^~~~~~~~~
                       &
/usr/include/string.h:141:39: note: passing argument to parameter '__dest' here
extern char *strcpy (char *__restrict __dest, const char *__restrict __src)
                                      ^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
2 errors generated.
make: *** [<builtin>: tictactoe] Error 1
1

There are 1 answers

0
ikegami On

arr is defined as char arr[3][3], so arr[l][k] is a char.

strcpy expects a char *, a pointer to a char, and more specifically a pointer to the first of a series of char to which it will copy a string (a NUL-terminated sequence of char values).

Looks like you want arr[l][k] = 'x';.


Other issues:

  • Does it really make sense to initalize arr that way?
  • If k is the horizontal offset, why do you use it to determine whether x or o should be used?
  • Why isn't var used anywhere?
  • Why do you attempt to loop over every position?
  • Why do you skip the first column when you do?