简体   繁体   English

C程序“预期”)之前“ {”令牌之前的Makefile错误

[英]Makefile error on C program “expected ‘)’ before ‘{’ token”

I get an error when I try to make the Makefile on the following C program. 尝试在以下C程序上制作Makefile时出现错误。

int main()
{
    char  filename_src[101], filename_dest[101];

    printf("\nSource file: ");
    gets_s(filename_src, 100);

    printf("\nDestination filename: ");
    gets_s(filename_dest, 100);

    if(copy_file(filename_src, filename_dest) == 0)
        printf("Copy Successful\n");
    else
        fprintf(stderr, "Error during copy!");

    copyfile( filename_src, filename_dest );
}

int copyfile( const char *test1, const char *test2 )
{
    int infile, outfile;
    ssize_t nread;
    char buffer[BUFSIZE];

    if( ( infile = open(test1, O_RDONLY) ) == -1 )
      return (-1);

    if( ( outfile = open(test2,O_WRONLY|O_CREAT|O_TRUNC,PERM ) == -1)
    {
        close(infile);
        return (-2);
    }
    /* now read from test1 BUFSIZE chars at a time*/
    while( (nread = read(infile, buffer, BUFSIZE) ) > 0)
    {
        /*write buffer to output file*/
        if( write(outfile, buffer, nread) < nread )
        {
            close(infile);
            close(outfile);
            return (-3);        /*write error*/
        }
    }

    close(infile);
    close(outfile);

    if( nread == -1 )
      return (-4);              /*error on last read*/

    else
      return (0);               /*all is well */
}

This is my C program. 这是我的C程序。 I get the error "expected ')' before '{' token" when I try to make the Makefile on terminal. 尝试在终端上制作Makefile时,出现“ {'令牌”之前的错误“ expected')”。 Can anyone tell me where the problem in my code is? 谁能告诉我代码中的问题在哪里?

Thank you 谢谢

if  ( ( outfile = open(test2,O_WRONLY|O_CREAT|O_TRUNC,PERM ) == -1)
    ^ 2               1                                    1      2 

As you can see this parenthesis is unmatched. 如您所见,该括号是不匹配的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 c - 创建 makefile 导致错误“预期 ';', ',' or ')' before '*' token” - c - creating a makefile causes error “expected ‘;’, ‘,’ or ‘)’ before ‘*’ token” 错误:预期 ')' 在 ';' 之前 c 程序上显示的令牌,用于检查字符串是否为回文 - error: expected ')' before ';' token showing on c program to check if a string is palindrome or not C错误:在&#39;...&#39;标记之前预期&#39;;&#39;,&#39;,&#39;或&#39;)&#39; - C error: expected ';', ',' or ')' before '…' token C中“ *”令牌错误之前的预期“)” - expected ')' before '*' token error in c C错误:在&#39;=&#39;标记前应为&#39;;&#39;,&#39;,&#39;或&#39;)&#39; - C -error: expected ';', ',' or ')' before '=' token C:错误:预期&#39;)&#39;之前&#39;;&#39; 代币 - C: error: expected ')' before ';' token &#39;{&#39;令牌C程序之前的预期表达式 - expected expression before ‘{’ token c program gcc编译器和makefile:错误:预期的标识符或&#39;&&#39;标记前的&#39;(&#39; - gcc compiler and makefile: error: expected identifier or ‘(’ before ‘&’ token C中的编译器错误:在&#39;*&#39;标记之前预期&#39;)&#39; - Compiler Error in C: expected ')' before '*' token C中的编译器错误-预期在&#39;!&#39;之前的&#39;)&#39; 令牌。 - Compiler Error in C — Expected ')' before '!' token.
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM