2

これは私のコードです

#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

これらのエラーが表示されるのはなぜですか?教えてください。ありがとうございます

4

3 に答える 3

7

この行の最後にセミコロンがありません:

void filecopy( FILE * a, FILE *b )

これは

void filecopy( FILE * a, FILE *b );

これは関数のプロトタイプだからです。

また、この行は合法ではありません C:

printf("no open".*argv);

これはおそらく次のようなものでなければなりません

printf("no open");

お役に立てれば!

于 2012-05-25T02:10:11.470 に答える
2

宣言はセミコロンで終わる必要があります

void filecopy( FILE * a, FILE *b );

(これはメイン関数内の宣言であり、後で来る関数定義ではありません。)

于 2012-05-25T02:11:11.840 に答える
2

セミコロンがありません。

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


この行:

printf("no open".*argv);

意味がありません。それはどういう意味でしたか?

于 2012-05-25T02:19:32.377 に答える