【正文】
case 9:exit(0)。 case 8:output()。 case 7:append()。 case 6: deleted()。 case 5:modify()。 case 4:search3()。 case 3:search2()。 case 2:search1()。 case 1:readfile()。 switch(m) { case 0:creat()。 scanf(%d,amp。 printf(\n)。 printf(\t\t8printf\n)。 printf(\t\t6delete\n)。 printf(\t\t4 serch as roomnumber\n)。 printf(\t\t2 serch as name\n)。 printf(\t\t0creat a new datafile\n)。 // m 用于控制菜單的選擇項 flag 用于控制菜單彈出 while(flag) { printf(%33s\n,thefile)。 fclose(fp)。 } else rewind(fp)。) //刪除確認按鈕 { fseek(fp,offset,SEEK_SET)。 if(m==39。 scanf(%s,amp。 printf(%10s%20s%50s\n,personname,personxh,personfh)。 break。 fscanf(fp,%s%s%s\n,personname,personxh,personfh)。 exit(0)。 if((fp=fopen(filename,r+))==NULL) { printf(\n can39。 printf(\n please enter the name you want to delete : )。 personnode *person。 long offset。 } void deleted() //刪除函數(shù) 用于刪除指定學(xué)生姓名的記錄 { int k=0。 } 《 宿舍管理系統(tǒng)的設(shè)計與實現(xiàn) 》 第 25 頁 共 27 頁 else printf(\n sorry, there is not the current of this people \n)。 fseek(fp,offset,SEEK_SET)。 printf(\n please enter the new studentname,studentnumber and roomnumber : )。 } } if(k) //相同 輸出記錄并進行修改 { printf(\n hava got it,the current is: )。 if(!strcmp(namekey,personname)) //比較是否相同 如 { k=1。 } while(!feof(fp)) { offset=ftell(fp)。t open thefile)。 scanf(%s,namekey)。 person=(personnode *)malloc(sizeof(personnode))。 char namekey[8]。 } void modify() //更新函數(shù) 用于修改指定學(xué)生姓名的記錄 { int k=0。 fprintf(fp,%10s%20s%50s\n,personname,personxh,personfh)。 } printf(\n please enter the name,studentnumber and roomnumber \n)。t open the file)。 person=(personnode *)malloc(sizeof(personnode))。 fclose(fp)。 k=1。 if(!strcmp(fhkey,personfh)) //比較是否相同 相同則輸出 《 宿舍管理系統(tǒng)的設(shè)計與實現(xiàn) 》 第 23 頁 共 27 頁 結(jié)果 否則輸出未找到記錄 { printf(\n\n have got it,the current is:)。 exit(0)。 if((fp=fopen(filename,rb))==NULL) { printf(\n can39。 printf(\n please enter the roomnumber you want to serch:)。 personnode *person。 } void search3() //按房號搜索函數(shù) { int k=0。 } } if(!k) printf(\n\n sorry,there is not the current of thiss people \n)。 printf(%10s%20s%50s\n,personname,personxh,personfh)。 } while(!feof(fp)) { fscanf(fp,%s %s %s\n,personname,personxh,personfh)。t open the file )。 scanf(%s,xhkey)。 person=(personnode *)malloc(sizeof(personnode))。 char xhkey[16]。 fclose(fp)。 k=1。 if(!strcmp(namekey,personname)) //比較是否相同 相同則輸出結(jié)果 否則輸出未找到記錄 { printf(\n\n have serched,the courrent is:)。 exit(0)。 if((fp=fopen(filename,rb))==NULL) { printf(\n can39。 printf(\n please enter the namehead you need :)。 personnode *person。 } void search1() // 按 姓名搜索函數(shù) { int k=0。 } fclose(fp)。 while(!feof(fp)) //次循環(huán)用于 輸出文件 { fscanf(fp,%s%s%s\n,personname,personxh,personfh)。 printf(%35s\n,thefile(thefile hava printf as studentnumber))。 ////若 a 為 1,則學(xué)號已有序排列,跳出總循環(huán),輸出文件 《 宿舍管理系統(tǒng)的設(shè)計與實現(xiàn) 》 第 20 頁 共 27 頁 } rewind(fp)。 //a 為 1 說明學(xué)號已經(jīng)有序 跳出循環(huán) rewind(fp)。}