Incompatible pointer to character conversion

前端 未结 2 1660
失恋的感觉
失恋的感觉 2021-01-29 11:50

I\'m writing a program to write card values into a 52 spot character multi-dimensional array. This program is one test array that I will write as a function into the main progra

相关标签:
2条回答
  • 2021-01-29 12:09

    You need to doing a strcpy and not assigning string literals directly. Also, the array usage is wrong.

    The code should be like below:

    #include <stdio.h>
    #include <string.h>
    
    int main ()
    {
        char CardValue[52][6];
        int i;
    
       /* Not clear what you are trying in the below 2 lines. But, it'll not work :-) */
        /*CardValue[i][6]=i;
        CardValue[i];*/    
    
        for (i=0;i<52;i++)
        {
    
            switch (i%13)
            {
                case '0': strcpy(CardValue[i],"ACE");
                break;
    
                case '1': strcpy(CardValue[i],"2");
                break;
    
              /** Do the same way for other case **/
    
            }
         }
    }
    
    0 讨论(0)
  • 2021-01-29 12:29

    You should #include <string.h> and do something like this:

    case '0': strcpy(CardValue[i],"ACE");

    etc. Also note, that CardValue[i]; has no effect at all. You should also remove CardValue[i][6]=i;, I don't really know what you meant by that, but it surely should not be there.

    0 讨论(0)
提交回复
热议问题