标签:ESS fscanf 字节 eve 实验 str print 考证 计算
#include<stdio.h> #include<stdlib.h> int main() { FILE *fp; char ch; fp=fopen("file1.dat","rb"); while(!feof(fp)) { ch=fgetc(fp); putchar(ch); } fclose(fp); return 0; }
#include <stdio.h> #include <stdlib.h> #include <string.h> const int N = 10; typedef struct student { long int id; char name[20]; float objective; float subjective; float sum; char level[10]; }STU; void input(STU s[], int n); void output(STU s[], int n); void process(STU s[], int n); int main() { STU stu[N]; printf("录入%d个考生信息: 准考证号,姓名,客观题得分(<=40),操作题得分(<=60)\n", N); input(stu, N); printf("\n对考生信息进行处理: 计算总分,确定等级\n"); process(stu, N); printf("\n打印考生完整信息: 准考证号,姓名,客观题得分,操作题得分,总分,等级\n"); output(stu, N); system("pause"); return 0; } void input(STU s[], int n) { int i; FILE *fp; fp=fopen("examinee.txt","r"); if(!fp) exit(0); for(i=0;i<n;i++) fscanf(fp, " %d %s %f %f\n",&s[i].id, s[i].name, &s[i].objective, &s[i].subjective); fclose(fp); } void output(STU s[], int n) { FILE *fh1; int i; for(i=0;i<n;i++) printf(" %d\t %s\t %.2f\t %.2f\t %.2f\t %s\n",s[i].id,s[i].name,s[i].objective,s[i].subjective,s[i].sum,s[i].level); fh1=fopen("result.txt","w"); if(fh1==0) exit(0); while(!feof(fh1)){ for(i=0;i<n;i++) fprintf(fh1,"%d\t %s\t %.2f\t %.2f\t %.2f\t %s\n",s[i].id,s[i].name,s[i].objective,s[i].subjective,s[i].sum,s[i].level); fclose(fh1); } } void process(STU s[], int n) { int i,j; STU k; for(i=0;i<N;i++) s[i].sum=s[i].objective+s[i].subjective; for(i=0;i<n;i++) for(j=0;j<n;j++) if(s[j].sum<s[j+1].sum){ k=s[j]; s[j]=s[j+1]; s[j+1]=k; } strcpy(s[0].level,"优秀"); for(i=1;i<5;i++) strcpy(s[i].level,"合格"); for(i=5;i<10;i++) strcpy(s[i].level,"不及格"); }
总结:太难了
标签:ESS fscanf 字节 eve 实验 str print 考证 计算
原文地址:https://www.cnblogs.com/ras123/p/12114921.html