我似乎无法在运行名为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

关于解引用和语法,我遗漏了什么??

最佳答案

您需要重新排列这条线上的通话:

inbuf = atoi(factorial(inbuf*));

应该是
int answ = factorial(atoi(inbuf));

*假设所有其他代码都有效,但我认为您需要将inbuf的声明从char *inbuf[MSGSIZE];更改为char inbuf[MSGSIZE];

10-08 09:33