指针数组警告 "initialization from incompatible pointer type"

Warning in array of pointers "initialization from incompatible pointer type"

我在这里问的问题很容易解决。代码工作正常,但这个警告让我很烦!

//initailize array elements
    char ZeroA[6]   = {0xC0,0x07,0x40,0x04,0xC0,0x07,};
    char OneA[6]    = {0x80, 0x04, 0xC0, 0x07, 0x00, 0x04,};
    char TwoA[6]    = {0x40, 0x07, 0x40, 0x05, 0xC0, 0x05,};
    char ThreeA[6]  = {0x40, 0x05, 0x40, 0x05, 0xC0, 0x07,};
    char FourA[6]   = {0x80, 0x03, 0x00, 0x02, 0x80, 0x07,};
    char FiveA[6]   = {0xC0, 0x05, 0x40, 0x05, 0x40, 0x07,};
    char SixA[6]    = {0xC0,0x05,0x40,0x05,0x40,0x07,}; 
    char SevenA[6]  = {0x40,0x04,0x40,0x03,0xC0,0x00,};
    char EightA[6]  = {0xC0,0x07,0x40,0x05,0xC0,0x07,};
    char NineA[6]   = {0xC0,0x05,0x40,0x05,0xC0,0x07,};
    char TenA[6]    = {0x00,0x01,0x80,0x03,0x00,0x01,};

int *mCount;     //address holder
char var = 4;    //Just random number for illustration

int *XYZ[11]={&ZeroA,&OneA,&TwoA,&ThreeA,&FourA,&FiveA,&SixA,&SevenA,&EightA,&NineA,&TenA};

mCount = XYZ[Var];   

ZeroA 等一个是指向 char 元素数组的指针。 &ZeroA 保存数组指针的地址 ZeroA 所以要保存它你需要 char **

在你的例子中正确的做法是这样的: char *XYZ[11]={ZeroA,OneA,TwoA,ThreeA,FourA,FiveA,SixA,SevenA,EightA,NineA,TenA};

作为 amine.ahd 中断的延续,mCount 需要是一个字符指针。

char *mCount;     //address holder

mCount = XYZ[var];   

int i = 0;

for( i = 0; i < 6; i ++ )
 printf( "%c ", mCount[i] );

插入几行代码进行测试。虽然它打印的是白色字符,但它似乎可以正常工作。更重要的是,没有编译警告。