CodePudding user response:
# include & lt; stdio.h>
# include & lt; Stdlib. H>
# include & lt; String. H>
Struct sp
{
Int xuehao;
/*
A former
Char xingroing [4].
Char xingbie [1].
Char kecheng [7].
Instead of */
Char xingroing [9].
Char xingbie [3].
Char kecheng [15].
//reasons: Chinese characters of two bytes (char), and output string \ 0 at the end, such as "male" includes three bytes
Int chengji;
};
Int main (uoid)
{
int j;
Double jigelv;
Int jige=O;
Int count=O;
Int flag=O;
Char chazhao [15].//former char chazhao [7];
The struct student sp;
The FILE * fp.
Printf (" please input to compute the pass rate of course name: ");
The scanf (" % s ", chazhao);
Printf (" \ n the calculation results for: \ n ");
Fp=fopen (" XSCJ. TXT ", "r"); I
If (fp==NULL)
{
Printf (" can not open the file! \n");
exit(1);
}
//note: the following statements is easy to spill
J=fscanf (fp, "% s % d % d % s % s", & amp; Student xuehao, student xingming, student. Xingbie, student. Kecheng, & amp; Student. Chengji);
While (j==5) {
flag=1;
If (STRCMP (student kecheng, chazhao)==O)
{
//the following statement error
//printf (" % d % s % c % s % d ", & amp; Student xuehao, student xingming, student. Xingbie, student. Kecheng, & amp; Student. Chengji);
//to
Printf (" % d % d % s % c % s ",/* & amp; */student xuehao, student xingming, student. Xingbie, student. Kecheng,/* & amp; */student. Chengji);
//reasons: not directly with data array using printf don't address,
flag=1;
J=fscanf (fp, "% s % d % d % s % s", & amp; Student xuehao, student xingming, student. Xingbie, student. Kecheng, & amp; Student. Chengji);
//add the following statement
count++;
If (student. Chengji & gt;=60) jige++;//to (including) 60 as to pass the
//reason: count when using the
}
}
If (flag==O)
{
Printf (" file no name for \ "% s " course \ n ", chazhao);
}
If (flag==1)
{
//change my statement
//jigelv=jige/count;
//printf (" course \ "% s " there are % d candidate, including pass % d, the pass rate for % f ", chazhao, count, jige, jigelv);
Jigelv=(double) jige/count;
Printf (" course \ "% s \ % d person to learn, including pass % d, the pass rate for % lf"/* front instead lf */f, chazhao, count, jige, jigelv);
//reasons: jigelv is double, and jige and count are int, need to type conversion, float with f, double with lf
}
The return O;
}
For reference, also, the building Lord, you should learn English
CodePudding user response:
Should be an array of the building Lord, speaking, reading and writing the definition, the array length is too small, need to consider '\ 0'