insertnu.c

来自「设计一个学生成绩管理系统」· C语言 代码 · 共 68 行

C
68
字号
#include"jinhe.h"
void insert_with_number()
{ struct student stu[M],temp;
  extern char filename[15];
  FILE *fp;
  int i,j,k;
  float temp1;
  if((fp=fopen(filename,"rb"))==NULL)
  { clrscr();
    gotoxy(15,15);
    printf("Cannot open file.Please press any key return.");
    getch();
    return;
  }
  fread(&stu[0],LEN,1,fp);
  for(i=0;stu[i].no;) fread(&stu[++i],LEN,1,fp);
  fclose(fp);
  clrscr();
  gotoxy(5,2);
  printf("****************Computer technology and science 2 ban****************");
  gotoxy(10,3);
  printf("--Input the student's message you want insert--");
  gotoxy(5,4);
  printf("|-------------------------------------------------------------------|");
  gotoxy(5,5);
  printf("|--NUMBER--|-----NAME------|-SEX-|-ENGLI-|-COMPE-|-MATH-|-CPR-|-AVE-|");
  gotoxy(5,6);
  printf("|----------|---------------|-----|-------|-------|------|-----|-----|");
  gotoxy(5,7);printf("|");
  gotoxy(16,7);printf("|");
  gotoxy(32,7);printf("|");
  gotoxy(38,7);printf("|");
  gotoxy(46,7);printf("|");
  gotoxy(54,7);printf("|");
  gotoxy(61,7);printf("|");
  gotoxy(67,7);printf("|");
  gotoxy(73,7);printf("|");
  gotoxy(6,7);scanf("%ld",&stu[i].no);
  gotoxy(17,7);scanf("%s",&stu[i].name);
  gotoxy(33,7);scanf("%s",&stu[i].sex);
  gotoxy(39,7);scanf("%f",&temp1); stu[i].english=temp1;
  gotoxy(47,7);scanf("%f",&temp1); stu[i].computer=temp1;
  gotoxy(55,7);scanf("%f",&temp1); stu[i].maths=temp1;
  gotoxy(62,7);scanf("%f",&temp1); stu[i].c_programe=temp1;
  stu[i].average=(stu[i].english+stu[i].computer+stu[i].c_programe+stu[i].maths)/4;
  gotoxy(68,7);printf("%.1lf",stu[i].average);
  gotoxy(5,8);printf("|----------|---------------|-----|-------|-------|------|-----|-----|");
  j=i+1;
  stu[j].no=0;
  if((fp=fopen(filename,"wb"))==NULL)
  { clrscr();
    gotoxy(15,15);
    printf("Cannot open file. Press any key return.");
    getch();
    return;
  }
  for(i=0;i<=j;i++)
    { if(fwrite(&stu[i],LEN,1,fp)!=1)
	 printf("file write error\n");
	 if(stu[i].no==0) break;}
  fclose(fp);
  clrscr();
  gotoxy(5,15);
  printf("Insert success! Press any key to sort with the number from low to high!");
  getch();
  sort_with_number();
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?