《C语言程序设计基础》上机实验报告(模版)

(F1+mid*sizeof(WORKERBASIC))->age,(F1+mid*sizeof(WORKERBASIC))->name); printf(\ } PrintPause(); return 0; }

int EditByage(WORKERBASIC *F1,int n) /*按年龄查找*/ { int a,flag=0,i; printf(\ printf(\ for(i=0;iage, (F1+i*sizeof(WORKERBASIC))->name); printf(\ printf(\ scanf(\ getchar(); for(i=0;iage)) { if(flag==0) { printf(\ printf(\ flag=1; } printf(\ (F1+i*sizeof(WORKERBASIC))->age, (F1+i*sizeof(WORKERBASIC))->name); } } if (flag==0) { printf(\ } else printf(\ PrintPause(); return 0;

}

int Edit() /*查找*/ { WORKERBASIC load,*F1; int n=0,key=0,i; FILE *fp=NULL; cleanscreen(); if ((fp=fopen(\ { printf(\ PrintPause(); return 0; } while(!feof(fp)) /*统计职工的数量*/ { if (fread(&load,sizeof(WORKERBASIC),1,fp)==1) n++; } fclose(fp); if (n==0) { printf(\ PrintPause(); return 0; } F1=(WORKERBASIC *)malloc(n*sizeof(WORKERBASIC)); /*按职工的人数申请内存空间*/ fp=fopen(\ for(i=0;i

printf(\ printf(\ printf(\ printf(\ printf(\ or Esc?\\n\ key=getch(); switch(key) { case '1': key=EditByNo(F1,n); break; case '2': key=EditByName(F1,n); break; case '3': key=EditByage(F1,n); break; } } free(F1); return 0; }

int Modify() { WORKER *head=NULL,*t=NULL,*load=NULL; FILE *fp=NULL; char str[20]; int num; cleanscreen(); load=(WORKER *)malloc(sizeof(WORKER)); if((fp=fopen(\ { printf(\ PrintPause(); return 0; } head=t=load; if (fread(load,sizeof(WORKERBASIC),1,fp)!=1) { printf(\ PrintPause(); return 0; } while(!feof(fp))

/*修改*/

{ load=(WORKER *)malloc(sizeof(WORKER)); t->next=load; if (fread(load,sizeof(WORKERBASIC),1,fp)!=1) break; t=load; } t->next=NULL;/*创建链表完成*/ fclose(fp); t=head; Scan(); printf(\ printf(\ scanf(\ getchar(); num=atoi(str); /*把字符串转换为长整型数*/ if

((strcmp(t->workerinfo.name,str)==0)||(num==t->workerinfo.No)||(num==t->workerinfo.age)) { printf(\ scanf(\ getchar(); printf(\ scanf(\ getchar(); printf(\ scanf(\ getchar(); printf(\ fp=fopen(\ t=head; if (head!=NULL) { fwrite(t,sizeof(WORKERBASIC),1,fp); while(t->next!=NULL) { t=t->next; if(fwrite(t,sizeof(WORKERBASIC),1,fp)!=1) { printf(\ PrintPause(); break;

} } free(head); fclose(fp); } PrintPause(); return 0; } /*存入文件(目标在首地址)*/ while(t->next!=NULL) { t=t->next; if

((strcmp(t->workerinfo.name,str)==0)||(num==t->workerinfo.No)||(num==t->workerinfo.age)) { printf(\ scanf(\ getchar(); printf(\ scanf(\ getchar(); printf(\ scanf(\ getchar(); printf(\ fp=fopen(\ t=head; if (head!=NULL) { fwrite(t,sizeof(WORKERBASIC),1,fp); while(t->next!=NULL) { t=t->next; if(fwrite(t,sizeof(WORKERBASIC),1,fp)!=1) { printf(\ PrintPause(); break; } }/*存入文件(当不在首地址的时候)*/ free(head); fclose(fp); } }

联系客服:779662525#qq.com(#替换为@) 苏ICP备20003344号-4