Zeynep
Zeynep

Reputation: 1

C Programing [Error] expected declaration or statement at end of input

I have the following code. However I get the expected declaration or statement at end of input error when I try to compile it. Could you please tell me why am I getting this error?

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

}

Upvotes: 0

Views: 3453

Answers (1)

abelenky
abelenky

Reputation: 64730

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

Upvotes: 1

Related Questions