无法取消引用变量以使功能得到满足
|
我似乎无法在没有错误的情况下运行名为factorial()的函数。
首先,如果我有
inbuf = atoi(factorial(inbuf));
,gcc会吐出来,
main.c:103: warning: passing argument 1 of ‘factorial’ makes integer from pointer without a cast
如果我将其更改为inbuf = atoi(factorial(inbuf*));
,gcc会吐出,
main.c:103: error: expected expression before ‘)’ token
相关代码:
int factorial(int n)
{
int temp;
if (n <= 1)
return 1;
else
return temp = n * factorial(n - 1);
} // end factorial
int main (int argc, char *argv[])
{
char *inbuf[MSGSIZE];
int fd[2];
# pipe() code
# fork() code
// read the number to factorialize from the pipe
read(fd[0], inbuf, MSGSIZE);
// close read
close(fd[0]);
// find factorial using input from pipe, convert to string
inbuf = atoi(factorial(inbuf*));
// send the number read from the pipe to the recursive factorial() function
write(fd[1], inbuf, MSGSIZE);
# more code
} // end main
我缺少有关取消引用和语法的信息吗?
没有找到相关结果
已邀请:
2 个回复
吞睫素
应该
*假设所有其他代码都可以,但是我认为您需要将inbuf的声明从
更改为
凸晴
其次,您需要将inbuf转换为int才能将其传递给
。
正是这样做的。然后,获取该操作的结果,并将其转换回字符串,然后将其分配给inbuf:这就是
这样做的原因。