gpt4 book ai didi

C 编程 [错误] 输入末尾的预期声明或语句

转载 作者:行者123 更新时间:2023-11-30 16:39:58 24 4
gpt4 key购买 nike

我有以下代码。但是,当我尝试编译它时,我在输入错误末尾得到了预期的声明或语句。您能告诉我为什么会收到此错误吗?

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

}

最佳答案

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

关于C 编程 [错误] 输入末尾的预期声明或语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46865112/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com