gpt4 book ai didi

c - C语言无效转换错误

转载 作者:行者123 更新时间:2023-11-30 21:43:54 25 4
gpt4 key购买 nike

我有这个功能:

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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com