我有一些接收指向char []的指针的函数。C重定向指针
void foo(char *number, int size)
{
char tmp[size];
for(i=0;i<size;i++) //We look to see if the array number points to contains a 1
tmp[i] = (number[i]=='1'?'1':'0');//if not then add a 0.
*number = &tmp; //PROBLEM LINE
printMyPointer(number); //some function to print the contents of the array pointed to.
}
但我最难重定向我的指针。我认为这个例子会读作“改变指向这个地址的指针”。但是我收到一个编译器警告,“赋值使得指针没有一个强制转换[缺省情况下启用]”。我应该如何重定向我的指针?
它应该是'* number = tmp'。数组的行为类似于指针 – avmohan
v3ga,* number = tmp;返回相同的警告。 – user1695505
实际上它是'number = tmp' – avmohan