gpt4 book ai didi

c - 错误 :Assignment makes pointer from integer without a cast

转载 作者:行者123 更新时间:2023-12-04 00:44:09 25 4
gpt4 key购买 nike

int findNumber(char *exp,int i,int *num)    
{
int k=i;
char *p;
p=exp[i]; //<-- here
while(*p>='0'&&*p<='9')
{
(*num)=(*num)*10+(*p);
k++;
p++;
}
return k;
}

我不断收到该错误:(p=exp[i];)
我试图发送一个字符数组和 (i,num) 整数,
'i' 我只是暂时将它设置为 0,直到代码工作为止,所以不要关注它。但是该函数应该返回“exp”中第一个不是数字的字符的位置,并确保之前的所有字符都是数字。

最佳答案

pchar*所以你需要为它分配一个指针,但 exp[i]返回单个 char数组中的元素。尝试

p = &exp[i];

或者
p = (exp + i);

反而。

关于c - 错误 :Assignment makes pointer from integer without a cast,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14243969/

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