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;
}
, 당신은 잠시 범위의 끝 부분에 누락 된 닫는 브래킷을 가지고있다. 또한 사용하기 전에'fin'과'fout'을 검사해야합니다. 'fscanf'가 float을 읽지 못하면 0을 반환합니다. –
코드 포맷터/자동 인덱스를 사용하면 쉽게 이런 문제를 피할 수 있습니다. 편집자/IDE가 플러그인을 사용할 수 없다면 다른 도구/편집기를 사용하여 전환을 고려하십시오. – hyde
'#include'이 올바르지 않습니다. –
wildplasser