gpt4 book ai didi

c - 预期的声明错误(c错误)

转载 作者:行者123 更新时间:2023-12-04 09:41:07 24 4
gpt4 key购买 nike

这是我的代码

#include<stdio.h>

int main( int argc ,char *argv[] )
{
FILE *fp;
void filecopy( FILE * a, FILE *b )

if (argc == 1)
{
filecopy(stdin,stdout);
}

else
{
while(--argc > 0)
{
if ((fp = fopen(*++argv,"r")) == NULL)
{
printf("no open".*argv);
}
else
{
filecopy(fp,stdout);
fclose(fp);
}
}
}
return 0;
}

void filecopy ( FILE *ifp ,FILE *ofp )
{
int c;
while ( (c = getc(ifp)) != EOF)
{
putc(c , ofp);
}
}


这些是我的错误:

con.c: In function 'filecopy':
con.c:8: error: expected declaration specifiers before 'if'
con.c:13: error: expected declaration specifiers before 'else'
con.c:29: error: expected declaration specifiers before 'return'
con.c:30: error: expected declaration specifiers before '}' token
con.c:33: error: expected '=', ',', ';', 'asm' or '__attribute__' before '{' token
con.c:39: error: expected '{' at end of input
con.c: In function 'main':
con.c:39: error: expected declaration or statement at end of input


为什么我得到这些错误,请告诉我?
谢谢
苏丹汉树

最佳答案

您缺少分号。

void filecopy( FILE * a, FILE *b );  /* Put semi-colon on the end! */



这行:

printf("no open".*argv);


没有意义。您要执行的操作是什么意思?

关于c - 预期的声明错误(c错误),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10747621/

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