我有这个功能:
HOTEL* delh(HOTEL *h , int *n, int k)
{
int i;
HOTEL *p;
for(i=k; i<*n-1; i++)
{
h[i]= h[i+1];
}
p = (HOTEL *)realloc(h, (*n-1)*sizeof(*p) );
if (p==NULL)
{
return p;
}
*n = *n - 1;
return p;
}
其中 Hotel 是一个结构体。当我在 main 中调用此函数时,出现错误:从 'int' 到 'int*' 的转换无效|和错误:初始化 'HOTEL* delh(HOTEL*, int*, int)'| 的参数 2。我是这样做的:
case 13:
printf("Enter position: ");
scanf("%d", &k);
p = delh(h, n, k); //here is the error
if (p == NULL)
{
puts("memory was not reallocated");
}
else
{
h = p;
}
getch( );
break;
在此之前,我创建一个结构变量数组。
最佳答案
更改:
p=delh(h, n, k);
至:
p=delh(h, &n, k);
关于c - C语言无效转换错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28518414/