Sudhanshu Gupta
Sudhanshu Gupta

Reputation: 2315

Expected declaration error( c error)

this is my code

#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);
    }
}

these are my error:

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

Why am i getting these error please tell me ? thank you sudhanshu

Upvotes: 2

Views: 6747

Answers (3)

abelenky
abelenky

Reputation: 64730

You are missing a semi-colon.

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


This line:

printf("no open".*argv);

Makes no sense. What did you mean for it to do?

Upvotes: 1

Windows programmer
Windows programmer

Reputation: 8075

The declaration needs to end with a semicolon

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

(That's the declaration inside the main function, not the function definition which comes later.)

Upvotes: 1

templatetypedef
templatetypedef

Reputation: 373392

You're missing a semicolon at the end of this line:

void filecopy( FILE * a, FILE *b )

This should be

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

Because this is a function prototype.

Also, this line is not legal C:

printf("no open".*argv);

This should probably just be something like

printf("no open");

Hope this helps!

Upvotes: 6

Related Questions