gpt4 book ai didi

c - C 程序 "expected ‘)’ 上 ‘{’ 标记之前的 Makefile 错误”

转载 作者:行者123 更新时间:2023-11-30 18:54:33 26 4
gpt4 key购买 nike

当我尝试在以下 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 */
}

这是我的 C 程序。当我尝试在终端上创建 Makefile 时,出现错误“‘{’ token 之前预期有‘)’”。谁能告诉我代码中的问题出在哪里?

谢谢

最佳答案

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

正如您所看到的,这个括号是不匹配的。

关于c - C 程序 "expected ‘)’ 上 ‘{’ 标记之前的 Makefile 错误”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30226013/

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