我似乎无法在没有错误的情况下运行这个名为 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
我对取消引用和我的语法缺少什么?