C在输入结束时编程[错误]预期声明或语句

时间:2017-10-21 15:59:59

标签: c compiler-errors

我有以下代码。但是当我尝试编译它时,我在输入错误结束时得到了预期的声明或语句。 你能否告诉我为什么会收到这个错误?

/* 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;

}

1 个答案:

答案 0 :(得分: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);