发布时间 : 星期一 文章青岛科技大学大学老师C语言上机实验答案更新完毕开始阅读bdf27c8b680203d8ce2f241d
struct student t; for(i=0;i for(j=0;j if(stu[j].sum { t=stu[j]; stu[j]=stu[j+1]; stu[j+1]=t; } } void sort(struct student stu[ ],int p) { switch(p) { case 1: sortbystunum(stu); break; case 2: sortbystuname(stu); break; case 3: sortbymath(stu); break; case 4: sortbyphysics(stu); break; case 5: sortbycomputer(stu); break; case 6: sortbysum(stu); break; default: printf(\ } } void sortselect(int *select) { printf(\ printspace( ); printf(\ printf(\ printf(\ printf(\ printspace( ); printf(“\\nYour choice:”); scanf(\} void main( ) { int selectnum; struct student stu1[N]; readinformation(stu1); sortselect(&selectnum); while(selectnum!=0) { sort(stu1,selectnum); printinformation(stu1); sortselect(&selectnum); } } 3、#include { FILE *fp_in,*fp_out; char infile[20],outfile[20]; printf(“Enter the infile name:”); scanf(“%s”,infile); printf(“Enter the outfile name:”); scanf(“%s”,outfile); if((fp_in=fopen(infile,“r”)==NULL) { printf(“Can’t open file:%s”,infile); exit(1); } if((fp_out=fopen(outfile,“w”)==NULL) { printf(“Can’t open file:%s”,outfile); exit(1); } while(!feof(fp_in)) fputc(fgetc(fp_in),fp_out); fclose(fp_in); fclose(fp_out); } 4、#include void main( ) { FILE *fp; char str[100]; int i; if((fp=fopen(“test”,“w”))==NULL) { printf(“Cannot open the file.\\n”); exit(0); } printf(“Input a string:”); gets(str); /*读入一行字符串*/ for(i=0;str[i]&&i<100;i++) /*处理该行中的每一个字符*/ { if(str[i]>=‘a’&&str[i]<=‘z’) /*若是小写字母*/ str[i]-=‘a’-‘A’; /*将小写字母转换为大写字母*/ fputc(str[i],fp); /*将转换后的字符写入文件*/ } fclose(fp); /*关闭文件*/ fp=fopen(“test”,“r”); /*以读方式打开文本文件*/ fgets(str,100,fp); /*从文件中读入一行字符串*/ printf(“%s\\n”,str); fclose(fp); }