2017-10-21 7 views
0

私は次のコードを持っています。しかし、私はそれをコンパイルしようとすると、入力エラーの終わりに期待される宣言またはステートメントを取得します。 このエラーが発生する理由を教えてください。Cプログラミング入力の終了時に[エラー]予想される宣言またはステートメント

/* File steelclass.c 

This program reads a yield tensile strength from the file steelclassin.txt, calls the 
function classfunc to determine the corresponding class and then the main program writes 
the strength and corresponding class to a file steelclassout.txt. This continues until the 
end of the input file is reached. 

*/ 

#include<stdio.h.> 

char classfunc(float s); 

int main (void) 
{ 



    float str; 
    char cls; 

    FILE * fin = fopen("steelclassin.txt", "r"); 
    FILE * fout = fopen("steelclassout.txt", "w"); 

    fprintf(fout, "Tensile strength Class\n"); 
    fprintf(fout, "------------------------\n"); 

    while (fscanf(fin, "%f", &str)!= EOF){ 
    cls = classfunc(str); 
    fprintf(fout, "%f     %c\n", str, cls); 


    fclose(fout); 
    system("steelclassout.txt"); 
    return 0; 

} 

char classfunc(float s) 
{ 



    char myClass; 

    if(s >= 1000.0){ 
     myClass = 'A'; 
    }else if(s >= 800.0){ 
     myClass = 'B'; 
    }else if (s >= 600.0){ 
     myClass = 'C'; 
    }else if (s >= 400.0){ 
     myClass = 'D'; 
    }else{ 
     myClass = 'E'; 
    } 

    return myClass; 

} 
+0

これはまさにあなたがコンパイルしようとしているコードである場合は、しばらくのスコープの終わりに欠けている閉じ括弧を持っています。また、使用する前に 'fin'と' fout'をチェックしてください。 'fscanf'が浮動小数点の読み込みに失敗した場合、0を返します。 –

+0

コードフォーマッタ/自動インデントを使用して、このような問題を簡単に回避します。あなたのエディタ/ IDEがそれを行うことができない場合(プラグインでも)、別のツール/エディタを使ってそれを行い、切り替えを検討してください。 – hyde

+2

'#include 'が正しく表示されません。 – wildplasser

答えて

0
/* Where is the closing } for this opening bracket?!? 
            | 
            V 
    */ 
while (fscanf(fin, "%f", &str)!= EOF){ 
cls = classfunc(str); 
fprintf(fout, "%f     %c\n", str, cls); 
関連する問題