2012-05-25 3 views
2

예상 선언 오류 (C 오류가)

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

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

해야한다 : 당신에게

+1

'열려 있지 않음'. * argv'이란 무엇입니까? –

+0

실제로 미안하지만 ("no open", * argv); –

답변

2

당신은 세미콜론 누락로 종료 할 필요가있다.

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


이 라인 :

printf("no open".*argv); 

는 이해되지 않는다. 그게 무슨 뜻 이니?

+0

'printf (no open ", * argv);를 의미한다고해도 두 번째 매개 변수를 전달하는 것을 정당화하기 위해서는'% s' (또는 다른'% -formatter')가 필요합니다. – abelenky

7

당신은이 라인의 끝에 세미콜론이 누락 sudhanshu 감사합니다. 이 도움이

printf("no open".*argv); 

이 아마해야 뭔가 같은

printf("no open"); 

희망 :

또한,이 라인은 법적 C하지 않습니다!

+0

고맙습니다. –

2

선언은 세미콜론

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

(즉, 메인 함수 내부에 선언, 늦어도 오는 함수 정의입니다.)

관련 문제