不兼容的指针类型char**和char*错误

Nab*_*ter 1 c pointers

void decimal2binary(char *decimal, char *binary) {   
    //method information goes here    
}
Run Code Online (Sandbox Code Playgroud)

这是主要的

int main(int argc, char **argv) {

char *data[100];
if (argc != 4) {
    printf("invalid number of arguments\n");
    return 1;
}
if (strcmp(argv[1] , "-d")) {

    if (strcmp(argv[3] , "-b")) {
        decimal2binary(temp, data);
    }
    }
}
Run Code Online (Sandbox Code Playgroud)

现在我收到了这个错误

     warning: passing argument 2 of ‘decimal2binary’ from incompatible pointer type [enabled by default]

     note: expected ‘char *’ but argument is of type ‘char **’
Run Code Online (Sandbox Code Playgroud)

所以它说它们是不兼容的类型,但我必须使用argv来获取数据(我被问到的方式)还有其他方法吗?

Jas*_*son 8

将声明更改data为简单:

char data[100];
Run Code Online (Sandbox Code Playgroud)

你不需要一个可以键入的指针数组char,这就是你现在声明的代码.你只需要一个字节数组.我相信你的困惑源于这样一个事实:虽然数组不是指针,但它们在作为函数参数传递时会衰减成指向数组第一个元素的指针.所以简单地说decimal2binary(temp, data);,你传递一个指向第一个元素的指针data,在这种情况下你需要它指向一个指针char,而不是一个指针char*.