You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

C语言调用dayCheck函数时指针类型不匹配错误排查求助

指针类型不匹配错误排查:int** 无法转换为 int*

编译错误信息

Cannot convert int** to int* for argument 1 to void dayCheck(int*, int*, float*, float*, int, int, float*, char*, char*)

问题根源

你在timeLoop函数中调用dayCheck时,给多个指针类型参数额外加了&(取地址符),导致传入的是二级指针(比如int**),但dayCheck的形参要求的是一级指针(比如int*),类型不匹配触发编译错误。

看timeLoop的形参定义:

void timeLoop(int *startMonth, int *startDate, ..., float *hourlyRate, float *minRate, ..., float *totalSalary, int *shiftHours, int *shiftMins, char *restAns, char *restWorkAns)

这里的startDate、startMonth、hourlyRate等本身已经是一级指针(比如int*、float*),直接传递给dayCheck就符合要求;但你调用时写了&startDate,相当于取指针变量的地址,得到的是二级指针int**,和dayCheck的第一个形参int*类型冲突。

修正后的调用代码

把dayCheck调用中的所有&去掉,直接传递指针变量本身:

dayCheck(startDate, startMonth, hourlyRate, minRate, timeIN, timeOUT, totalSalary, shiftHours, shiftMins, restAns, restWorkAns);

额外提示

另外注意你restDayCheck函数里的循环条件存在逻辑错误:

// 原条件:逻辑或会导致永远判定无效,因为输入不可能同时等于y/Y/n/N
if (*restAns != 'y' || *restAns != 'Y' || *restAns != 'n' || *restAns != 'N')
// 应改为逻辑与:输入同时不是这四个值时才判定无效
if (*restAns != 'y' && *restAns != 'Y' && *restAns != 'n' && *restAns != 'N')

这个错误会导致无论输入什么,都会提示"Answer/s are invalid.",需要一并修正。

内容的提问来源于stack exchange,提问作者pikalvr ً

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.10 17:55:18