操作系統(tǒng)課程設(shè)計(jì)_第1頁(yè)
操作系統(tǒng)課程設(shè)計(jì)_第2頁(yè)
操作系統(tǒng)課程設(shè)計(jì)_第3頁(yè)
操作系統(tǒng)課程設(shè)計(jì)_第4頁(yè)
操作系統(tǒng)課程設(shè)計(jì)_第5頁(yè)
已閱讀5頁(yè),還剩61頁(yè)未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

課程設(shè)計(jì)學(xué)生學(xué)院計(jì)算機(jī)學(xué)院專業(yè)班級(jí)12(1)班學(xué)號(hào)學(xué)生姓名吳煒文指導(dǎo)教師李敏1月10日目錄1簡(jiǎn)樸文獻(xiàn)系統(tǒng)…………文獻(xiàn)系統(tǒng)一、實(shí)驗(yàn)?zāi)康?模擬文獻(xiàn)管理的功效,理解多種文獻(xiàn)的操作。二、實(shí)驗(yàn)內(nèi)容:1、設(shè)計(jì)一種10個(gè)顧客的文獻(xiàn)系統(tǒng),每次顧客可保存10個(gè)文獻(xiàn),一次運(yùn)行顧客能夠打開5個(gè)文獻(xiàn)2、程序采用二級(jí)文獻(xiàn)目錄(即設(shè)立主目錄[MFD])和顧客文獻(xiàn)目錄(UED)。另外,為打開文獻(xiàn)設(shè)立了運(yùn)行文獻(xiàn)目錄(AFD)。3、為了便于實(shí)現(xiàn),對(duì)文獻(xiàn)的讀寫作了簡(jiǎn)化,在執(zhí)行讀寫命令時(shí),只需改讀寫指針,并不進(jìn)行實(shí)際的讀寫操作。4、算法與框圖:a、因系統(tǒng)小,文獻(xiàn)目錄的檢索使用了簡(jiǎn)樸的線性搜索。b、文獻(xiàn)保護(hù)簡(jiǎn)樸使用了三位保護(hù)碼:允許讀寫執(zhí)行、對(duì)應(yīng)位為1,對(duì)應(yīng)位為0,則表達(dá)不允許讀寫、執(zhí)行。c、程序中使用的重要設(shè)計(jì)構(gòu)造以下:i

主文獻(xiàn)目錄和顧客文獻(xiàn)目錄(MFD、UFD)ii打開文獻(xiàn)目錄(AFD)(即運(yùn)行文獻(xiàn)目錄)規(guī)定:用高級(jí)語(yǔ)言編寫和調(diào)試一種簡(jiǎn)樸的文獻(xiàn)系統(tǒng),模擬文獻(xiàn)管理的工作過(guò)程。從而對(duì)多種文獻(xiàn)操作命令的實(shí)質(zhì)內(nèi)容和執(zhí)行過(guò)程有比較進(jìn)一步的理解。規(guī)定設(shè)計(jì)一種n個(gè)顧客的文獻(xiàn)系統(tǒng),每次顧客可保存m個(gè)文獻(xiàn),顧客在一次運(yùn)行中只能打開一種文獻(xiàn),對(duì)文獻(xiàn)必須設(shè)立保護(hù)方法,且最少有Create、delete、open、close、read、write等命令。

文獻(xiàn)系統(tǒng)算法的流程圖以下:三、源代碼及運(yùn)行成果:#include"stdio.h"#include"string.h"#include"conio.h"#include"stdlib.h"#defineMAXNAME25/*thelargestlengthofmfdname,ufdname,filename*/#defineMAXCHILD50/*thelargestchild*/#defineMAX(MAXCHILD*MAXCHILD)/*thesizeoffpaddrno*/typedefstruct/*thestructureofOSFILE*/{intfpaddr;/*filephysicaladdress*/intflength;/*filelength*/intfmode;/*filemode:0-ReadOnly;1-WriteOnly;2-ReadandWrite(default);*/charfname[MAXNAME];/*filename*/}OSFILE;typedefstruct/*thestructureofOSUFD*/{charufdname[MAXNAME];/*ufdname*/OSFILEufdfile[MAXCHILD];/*ufdownfile*/}OSUFD;typedefstruct/*thestructureofOSUFD'LOGIN*/{charufdname[MAXNAME];/*ufdname*/charufdpword[8];/*ufdpassword*/}OSUFD_LOGIN;typedefstruct/*fileopenmode*/{intifopen;/*ifopen:0-close,1-open*/intopenmode;/*0-readonly,1-writeonly,2-readandwrite,3-initial*/}OSUFD_OPENMODE;OSUFD*ufd[MAXCHILD];/*ufdandufdownfiles*/OSUFD_LOGINufd_lp;intucount=0;/*thecountofmfd'sufds*/intfcount[MAXCHILD];/*thecountofufd'sfiles*/intloginsuc=0;/*whetherloginsuccessfully*/charusername[MAXNAME];/*recordloginuser'sname22*/chardirname[MAXNAME];/*recordcurrentdirectory*/intfpaddrno[MAX];/*recordfilephysicaladdressnum*/OSUFD_OPENMODEifopen[MAXCHILD][MAXCHILD];/*recordfileopen/close*/intwgetchar;/*whethergetchar()*/FILE*fp_mfd,*fp_ufd,*fp_file_p,*fp_file;voidmain(){inti,j,choice1;charchoice[50];/*choiceoperation:dir,create,delete,open,delete,modify,read,write*/intchoiceend=1;/*whetherchoiceend*/char*rtrim(char*str);/*removethetrailingblanks.*/char*ltrim(char*str);/*removetheheadingblanks.*/voidLoginF();/*LOGINFileSystem*/voidDirF();/*DirFileSystem*/voidCdF();/*ChangeDir*/voidCreateF();/*CreateFile*/voidDeleteF();/*DeleteFile*/voidModifyFM();/*ModifyFileMode*/voidOpenF();/*OpenFile*/voidCloseF();/*CloseFile*/voidReadF();/*ReadFile*/voidWriteF();/*WriteFile*/voidQuitF();/*QuitFileSystem*/voidhelp();if((fp_mfd=fopen("c:\\osfile\\mfd","rb"))==NULL){fp_mfd=fopen("c:\\osfile\\mfd","wb");fclose(fp_mfd);}for(i=0;i<MAX;i++)fpaddrno[i]=0;textattr(BLACK*16|WHITE);clrscr();/*clearscreen*/LoginF();/*userlogin*/clrscr();if(loginsuc==1)/*LoginSuccessfully*/{while(1){wgetchar=0;if(choiceend==1){printf("\n\nC:\\%s>",strupr(dirname));}elseprintf("Badcommandorfilename.\nC:\\%s>",strupr(username));gets(choice);strcpy(choice,ltrim(rtrim(strlwr(choice))));if(strcmp(choice,"dir")==0)choice1=1;elseif(strcmp(choice,"creat")==0)choice1=2;elseif(strcmp(choice,"delete")==0)choice1=3;elseif(strcmp(choice,"attrib")==0)choice1=4;elseif(strcmp(choice,"open")==0)choice1=5;elseif(strcmp(choice,"close")==0)choice1=6;elseif(strcmp(choice,"read")==0)choice1=7;elseif(strcmp(choice,"modify")==0)choice1=8;elseif(strcmp(choice,"exit")==0)choice1=9;elseif(strcmp(choice,"cls")==0)choice1=10;elseif(strcmp(choice,"cd")==0)choice1=11;elseif(strcmp(choice,"help")==0)choice1=20;elsechoice1=12;switch(choice1){case1:DirF();choiceend=1;break;case2:CreateF();choiceend=1;if(!wgetchar)getchar();break;case3:DeleteF();choiceend=1;if(!wgetchar)getchar();break;case4:ModifyFM();choiceend=1;if(!wgetchar)getchar();break;case5:choiceend=1;OpenF();if(!wgetchar)getchar();break;case6:choiceend=1;CloseF();if(!wgetchar)getchar();break;case7:choiceend=1;ReadF();if(!wgetchar)getchar();break;case8:choiceend=1;WriteF();if(!wgetchar)getchar();break;case9:printf("\nYouhaveexitedthissystem.");QuitF();exit(0);break;case10:choiceend=1;clrscr();break;case11:CdF();choiceend=1;break;case20:help();choiceend=1;break;default:choiceend=0;}}}elseprintf("\nAccessdenied.");}voidhelp(void){printf("\nTheCommandList\n");printf("\nCdAttribCreatModifyReadOpenClsDeleteExitClose\n");}char*rtrim(char*str)/*removethetrailingblanks.*/{intn=strlen(str)-1;while(n>=0){if(*(str+n)!=''){*(str+n+1)='\0';break;}elsen--;}if(n<0)str[0]='\0';returnstr;}char*ltrim(char*str)/*removetheheadingblanks.*/{char*rtrim(char*str);strrev(str);rtrim(str);strrev(str);returnstr;}voidLoginF()/*LOGINFileSystem*/{charloginame[MAXNAME],loginpw[9],logincpw[9],str[50];inti,j,flag=1;chara[25];intfindout;/*loginusernotexist*/char*rtrim(char*str);/*removethetrailingblanks.*/char*ltrim(char*str);/*removetheheadingblanks.*/voidInputPW(char*password);/*inputpassword,use'*'replace*/voidSetPANo(intRorW);/*Setphysicaladdressnum*/while(1){findout=0;printf("\n\nLoginName:");gets(loginame);ltrim(rtrim(loginame));fp_mfd=fopen("c:\\osfile\\","rb");for(i=0;fread(&ufd_lp,sizeof(OSUFD_LOGIN),1,fp_mfd)!=0;i++)if(strcmp(strupr(ufd_lp.ufdname),strupr(loginame))==0){findout=1;strcpy(logincpw,ufd_lp.ufdpword);}fclose(fp_mfd);if(findout==1)/*userexist*/{printf("LoginPassword:");InputPW(loginpw);/*inputpassword,use'*'replace*/if(strcmp(loginpw,logincpw)==0){strcpy(username,strupr(loginame));strcpy(dirname,username);fp_mfd=fopen("c:\\osfile\\","rb");for(j=0;fread(&ufd_lp,sizeof(OSUFD_LOGIN),1,fp_mfd)!=0;j++){strcpy(str,"c:\\osfile\\");strcat(str,ufd_lp.ufdname);ufd[j]=(OSUFD*)malloc(sizeof(OSUFD));strcpy(ufd[j]->ufdname,strupr(ufd_lp.ufdname));fp_ufd=fopen(str,"rb");fcount[j]=0;for(i=0;fread(&ufd[j]->ufdfile[i],sizeof(OSFILE),1,fp_ufd)!=0;i++,fcount[j]++){ifopen[j][i].ifopen=0;ifopen[j][i].openmode=4;}fclose(fp_ufd);}fclose(fp_mfd);ucount=j;SetPANo(0);printf("\n\nLoginsuccessful!WelcometothisFileSystem\n\n");loginsuc=1;return;}else{printf("\n\n");flag=1;while(flag){printf("LoginFailed!PasswordError.TryAgain(Y/N):");gets(a);ltrim(rtrim(a));if(strcmp(strupr(a),"Y")==0){loginsuc=0;flag=0;}elseif(strcmp(strupr(a),"N")==0){loginsuc=0;flag=0;return;}}}}else{printf("NewPassword(<=8):");InputPW(loginpw);/*inputnewpassword,use'*'replace*/printf("\nConfirmPassword(<=8):");/*inputnewpassword,use'*'replace*/InputPW(logincpw);if(strcmp(loginpw,logincpw)==0){strcpy(ufd_lp.ufdname,strupr(loginame));strcpy(ufd_lp.ufdpword,loginpw);fp_mfd=fopen("c:\\osfile\\","ab");fwrite(&ufd_lp,sizeof(OSUFD_LOGIN),1,fp_mfd);fclose(fp_mfd);strcpy(username,strupr(loginame));strcpy(dirname,loginame);strcpy(str,"c:\\osfile\\");strcat(str,username);if((fp_ufd=fopen(str,"rb"))==NULL){fp_ufd=fopen(str,"wb");fclose(fp_ufd);}fp_mfd=fopen("c:\\osfile\\","rb");for(j=0;fread(&ufd_lp,sizeof(OSUFD_LOGIN),1,fp_mfd)!=0;j++){strcpy(str,"c:\\osfile\\");strcat(str,ufd_lp.ufdname);ufd[j]=(OSUFD*)malloc(sizeof(OSUFD));strcpy(ufd[j]->ufdname,strupr(ufd_lp.ufdname));fp_ufd=fopen(str,"rb");for(i=0;fread(&ufd[j]->ufdfile[i],sizeof(OSFILE),1,fp_ufd)!=0;i++,fcount[j]++){ifopen[j][i].ifopen=0;ifopen[j][i].openmode=4;}fclose(fp_ufd);}fclose(fp_mfd);ucount=j;SetPANo(0);printf("\n\nLoginSuccessful!WelcometothisSystem\n\n");loginsuc=1;return;}else{printf("\n\n");flag=1;while(flag){printf("LoginFailed!PasswordError.TryAgain(Y/N):");gets(a);ltrim(rtrim(a));if(strcmp(strupr(a),"Y")==0){loginsuc=0;flag=0;}elseif(strcmp(strupr(a),"N")==0){loginsuc=0;flag=0;return;}}}}}}voidSetPANo(intRorW)/*Setphysicaladdressnum,0-read,1-write*/{inti,j;if(RorW==0){if((fp_file_p=fopen("c:\\osfile\\file\\file_p","rb"))==NULL){fp_file_p=fopen("c:\\osfile\\file\\file_p","wb");fclose(fp_file_p);}fp_file_p=fopen("c:\\osfile\\file\\file_p","rb");for(i=0;fread(&j,sizeof(int),1,fp_file_p)!=0;i++)fpaddrno[j]=1;/*for(i=1;i<MAX;i++)if((i%13)==0)fpaddrno[i]=1;*/}else{fp_file_p=fopen("c:\\osfile\\file\\file_p","wb");/*for(i=1;i<MAX;i++)if((i%13)==0)fpaddrno[i]=0;*/for(i=0;i<MAX;i++)if(fpaddrno[i]==1)fwrite(&i,sizeof(int),1,fp_file_p);}fclose(fp_file_p);}voidInputPW(char*password)/*inputpassword,use'*'replace*/{intj;for(j=0;j<=7;j++){password[j]=getch();if((int)(password[j])!=13){if((int)(password[j])!=8)putchar('*');else{if(j>0){j--;j--;putchar('\b');putchar('');putchar('\b');}elsej--;}}else{password[j]='\0';break;}}password[j]='\0';}voidDirF()/*DirFileSystem*/{inti,j,count=0;charsfmode[25],sfpaddr[25],str[25];intExistD(char*dirname);/*WhetherDirNameExist,Exist-i,NotExist-0*/clrscr();if(strcmp(strupr(ltrim(rtrim(dirname))),"")!=0){printf("\n\nC:\\%s>dir\n",dirname);printf("\n%14s%16s%14s%10s%18s\n","FileName","FileAddress","FileLength","Type","FileMode");j=ExistD(dirname);for(i=0;i<fcount[j];i++){if((i%16==0)&&(i!=0)){printf("\nPressanykeytocontinue..");getch();clrscr();printf("\n%14s%16s%14s%10s%18s\n","FileName","FileAddress","FileLength","Type","FileMode");}itoa(ufd[j]->ufdfile[i].fpaddr,str,10);strcpy(sfpaddr,"file");strcat(sfpaddr,str);if(ufd[j]->ufdfile[i].fmode==0)strcpy(sfmode,"ReadOnly");elseif(ufd[j]->ufdfile[i].fmode==1)strcpy(sfmode,"WriteOnly");elseif(ufd[j]->ufdfile[i].fmode==2)strcpy(sfmode,"ReadAndWrite");elsestrcpy(sfmode,"Protect");printf("%14s%16s%14d%10s%18s\n",ufd[j]->ufdfile[i].fname,sfpaddr,ufd[j]->ufdfile[i].flength,"<FILE>",sfmode);}printf("\n%3dfile(s)\n",fcount[j]);}else{printf("\n\nC:\\>dir\n");printf("\n%14s%18s%8s\n","DirName","OwnFileCount","Type");for(i=0;i<ucount;i++){if((i%16==0)&&(i!=0)){printf("\nPressanykeytocontinue...");getch();clrscr();printf("\n%14s%18s%8s\n","DirName","OwnFileCount","Type");}printf("%14s%18d%8s\n",ufd[i]->ufdname,fcount[i],"<UFD>");count=count+fcount[i];}printf("\n%3ddir(s),%5dfile(s)\n",ucount,count);}}intExistD(char*dirname)/*WhetherDirNameExist,Exist-i,NotExist-0*/{inti;intexist=0;for(i=0;i<ucount;i++)if(strcmp(strupr(ufd[i]->ufdname),strupr(dirname))==0){exist=1;break;}if(exist)return(i);elsereturn(-1);}voidCdF()/*ExchangeDir*/{chardname[MAXNAME];char*rtrim(char*str);/*removethetrailingblanks.*/char*ltrim(char*str);/*removetheheadingblanks.*/intExistD(char*filename);/*WhetherFileNameExist,Exist-i,NotExist-0*/printf("\nPleaseinputDirName(cd..-Previousdir;DirNAME-cd[DirNAME]):");gets(dname);ltrim(rtrim(dname));if(ExistD(dname)>=0)strcpy(dirname,strupr(dname));elseif(strcmp(strupr(dname),"CD..")==0)strcpy(ltrim(rtrim(dirname)),"");elseprintf("\nError.\'%s\'doesnotexist.\n",dname);}voidCreateF()/*CreateFile*/{intfpaddrno,flag=1,i;charfname[MAXNAME],str[50],str1[50],strtext[255],a[25];charfmode[25];char*rtrim(char*str);/*removethetrailingblanks.*/char*ltrim(char*str);/*removetheheadingblanks.*/intFindPANo();/*findoutphysicaladdressnum*/intWriteF1();/*writefile*/intExistF(char*filename);/*WhetherFileNameExist,Exist-i,NotExist-0*/intExistD(char*dirname);if(strcmp(strupr(dirname),strupr(username))!=0){printf("\nError.Youmustcreatefileinyourowndir.\n");wgetchar=1;}else{printf("\nPleaseinputFileName:");gets(fname);ltrim(rtrim(fname));if(ExistF(fname)>=0){printf("\nError.Name\'%s\'hasalreadyexisted.\n",fname);wgetchar=1;}else{printf("PleaseinputFileMode(0-ReadOnly,1-WriteOnly,2-ReadandWrite,3-Protect):");gets(fmode);ltrim(rtrim(fmode));if((strcmp(fmode,"0")==0)||(strcmp(fmode,"1")==0)||(strcmp(fmode,"2")==0)||(strcmp(fmode,"3")==0)){fpaddrno=FindPANo();if(fpaddrno>=0){i=ExistD(username);strcpy(ufd[i]->ufdfile[fcount[i]].fname,fname);ufd[i]->ufdfile[fcount[i]].fpaddr=fpaddrno;ufd[i]->ufdfile[fcount[i]].fmode=atoi(fmode);ifopen[i][fcount[i]].ifopen=0;ifopen[i][fcount[i]].openmode=4;strcpy(str,"c:\\osfile\\file\\file");itoa(fpaddrno,str1,10);strcat(str,str1);fp_file=fopen(str,"wb");fclose(fp_file);fcount[i]++;while(flag){printf("Inputtextnow(Y/N):");gets(a);ltrim(rtrim(a));ufd[i]->ufdfile[fcount[i]-1].flength=0;if(strcmp(strupr(a),"Y")==0){fp_file=fopen(str,"wb+");ufd[i]->ufdfile[fcount[i]-1].flength=WriteF1();flag=0;}elseif(strcmp(strupr(a),"N")==0){flag=0;wgetchar=1;}}printf("\n\'%s\'hasbeencreatedsuccessfully!\n",fname);}else{printf("\nFail!NoDiskSpace.Pleaseformatyourdisk.\n");wgetchar=1;}}else{printf("\nError.FileMode\'sRangeis0-3\n");wgetchar=1;}}}}intExistF(char*filename)/*WhetherFileNameExist,Exist-i,NotExist-0*/{inti,j;intexist=0;intExistD(char*dirname);j=ExistD(dirname);for(i=0;i<fcount[j];i++)if(strcmp(strupr(ufd[j]->ufdfile[i].fname),strupr(filename))==0){exist=1;break;}if(exist)return(i);elsereturn(-1);}intFindPANo()/*findoutphysicaladdressnum*/{inti;for(i=0;i<MAX;i++)if(fpaddrno[i]==0){fpaddrno[i]=1;break;}if(i<MAX)return(i);elsereturn(-1);}intWriteF1()/*writefile*/{intlength=0;charc;printf("Pleaseinputtext(\'#\'standsforend):\n");while((c=getchar())!='#'){fprintf(fp_file,"%c",c);if(c!='\n')length++;}fprintf(fp_file,"\n");fclose(fp_file);return(length);}voidDeleteF()/*DeleteFile*/{charfname[MAXNAME];charstr[50],str1[50];inti,j,k,flag=1;chara[25];/*whetherdelete*/char*rtrim(char*str);/*removethetrailingblanks.*/char*ltrim(char*str);/*removetheheadingblanks.*/intExistF(char*filename);/*WhetherFileNameExist,Exist-i,NotExist-0*/intExistD(char*dirname);if(strcmp(strupr(dirname),strupr(username))!=0){printf("\nError.Youcanonlydeletefileinyourowndir.\n");wgetchar=1;}else{printf("\nPleaseinputFileName:");gets(fname);ltrim(rtrim(fname));i=ExistF(fname);if(i>=0){k=ExistD(username);if(ifopen[k][i].ifopen==1){printf("\nError.\'%s\'isinopenstatus.Closeitbeforedelete.\n",fname);wgetchar=1;}else{while(flag){printf("\'%s\'willbedeleted.Areyousure(Y/N):",fname);gets(a);ltrim(rtrim(a));if(strcmp(strupr(a),"Y")==0){fpaddrno[ufd[k]->ufdfile[i].fpaddr]=0;itoa(ufd[k]->ufdfile[i].fpaddr,str,10);for(j=i;j<fcount[k]-1;j++){strcpy(ufd[k]->ufdfile[j].fname,ufd[k]->ufdfile[j+1].fname);ufd[k]->ufdfile[j].fpaddr=ufd[k]->ufdfile[j+1].fpaddr;ufd[k]->ufdfile[j].flength=ufd[k]->ufdfile[j+1].flength;ufd[k]->ufdfile[j].fmode=ufd[k]->ufdfile[j+1].fmode;ifopen[k][j]=ifopen[k][j+1];}fcount[k]--;strcpy(str1,"c:\\osfile\\file\\file");strcat(str1,str);remove(str1);flag=0;printf("\n\'%s\'hasbeendeletedsuccessfully.\n",fname);wgetchar=1;}elseif(strcmp(strupr(a),"N")==0){printf("\nError.\'%s\'hasn\'tbeendeleted.\n",fname);wgetchar=1;flag=0;}}}}else{printf("\nError.\'%s\'doesnotexist.\n",fname);wgetchar=1;}}}voidModifyFM()/*ModifyFileMode*/{charfname[MAXNAME],str[50];inti,j,k,flag;charfmode[25];/*whetherdelete*/char*rtrim(char*str);/*removethetrailingblanks.*/char*ltrim(char*str);/*removetheheadingblanks.*/voidInputPW(char*password);/*inputpassword,use'*'replace*/voidSetPANo(intRorW);/*Setphysicaladdressnum*/intExistF(char*filename);/*WhetherFileNameExist,Exist-i,NotExist-0*/intExistD(char*dirname);if(strcmp(strupr(dirname),strupr(username))!=0){printf("\nError.Youcanonlymodifyfilemodeinyourselfdir.\n");wgetchar=1;}else{printf("\nPleaseinputFileName:");gets(fname);ltrim(rtrim(fname));i=ExistF(fname);if(i>=0){k=ExistD(username);if(ifopen[k][i].ifopen==1){printf("\nError.\'%s\'isinopenstatus.Closeitbeforemodify.\n",fname);wgetchar=1;}else{if(ufd[k]->ufdfile[i].fmode==0)strcpy(str,"readonly");/*FileMode*/elseif(ufd[k]->ufdfile[i].fmode==1)strcpy(str,"writeonly");elseif(ufd[k]->ufdfile[i].fmode==2)strcpy(str,"readandwrite");elsestrcpy(str,"Protect");printf("\'%s\'filemodeis%s.\n",fname,strupr(str));printf("Modifyto(0-readonly,1-writeonly,2-readandwrite,3-Protect):");gets(fmode);ltrim(rtrim(fmode));if(strcmp(fmode,"0")==0){ufd[k]->ufdfile[i].fmode=0;printf("\n\'%s\'hasbeenmodifiedtoREADONLYmodesuccessfully.\n",fname);wgetchar=1;}elseif(strcmp(fmode,"1")==0){ufd[k]->ufdfile[i].fmode=1;printf("\n\'%s\'hasbeenmodifiedtoWRITEONLYmodesuccessfully.\n",fname);wgetchar=1;}elseif(strcmp(fmode,"2")==0){ufd[k]->ufdfile[i].fmode=2;printf("\n\'%s\'hasbeenmodifiedtoREADANDWRITEmodesuccessfully.\n",fname);wgetchar=1;}elseif(strcmp(fmode,"3")==0){ufd[k]->ufdfile[i].fmode=3;printf("\n\'%s\'hasbeenmodifiedtoFORBIDmodesuccessfully.\n",fname);wgetchar=1;}else{printf("\nError.\'%s\'isnotmodified.\n",fname);wgetchar=1;}}}else{printf("\nError.\'%s\'dosenotexist.\n",fname);wgetchar=1;}}}voidOpenF()/*OpenFile*/{charfname[MAXNAME];charstr[25],str1[25],fmode[25];inti,k;char*rtrim(char*str);/*removethetrailingblanks.*/char*ltrim(char*str);/*removetheheadingblanks.*/intExistF(char*filename);/*WhetherFileNameExist,Exist-i,NotExist-0*/intExistD(char*dirname);if(strcmp(strupr(ltrim(rtrim(dirname))),"")==0){printf("\nError.Pleasechangetoufddirbeforeopen.\n");wgetchar=1;return;}printf("\nPleaseinputFileName:");gets(fname);ltrim(rtrim(fname));i=ExistF(fname);if(i>=0){k=ExistD(dirname);if(!ifopen[k][i].ifopen){if(ufd[k]->ufdfile[i].fmode==3){printf("\nError.Thefile\'smodeisFORBID.Cannotopen.\n");wgetchar=1;}else{printf("PleaseinputFileOpenMode(0-ReadOnly,1-WriteOnly,2-ReadandWrite):");gets(fmode);ltrim(rtrim(fmode));if((strcmp(fmode,"0")==0)||(strcmp(fmode,"1")==0)||(strcmp(fmode,"2")==0)){if(fmode[0]=='0')/*openfilewithreadonlymode*/{strcpy(str,"readonly");if((ufd[k]->ufdfile[i].fmode==0)||(ufd[k]->ufdfile[i].fmode==2))ifopen[k][i].ifopen=1;}elseif(fmode[0]=='1')/*openfilewithwriteonlymode*/{strcpy(str,"writeonly");if((ufd[k]->ufdfile[i].fmode==1)||(ufd[k]->ufdfile[i].fmode==2))ifopen[k][i].ifopen=1;}elseif(fmode[0]=='2')/*openfilewithreadandwritemode*/{strcpy(str,"readandwrite");if(ufd[k]->ufdfile[i].fmode==2)ifopen[k][i].ifopen=1;}if(ufd[k]->ufdfile[i].fmode==0)strcpy(str1,"readonly");/*FileMode*/elseif(ufd[k]->ufdfile[i].fmode==1)strcpy(str1,"writeonly");elseif(ufd[k]->ufdfile[i].fmode==2)strcpy(str1,"readandwrite");if(ifopen[k][i].ifopen==1){ifopen[k][i].openmode=atoi(fmode);if(ifopen[k][i].openmode==0)strcpy(str,"readonly");elseif(ifopen[k][i].openmode==1)strcpy(str,"writeonly");elseif(ifopen[k][i].openmode==2)strcpy(str,"readandwrite");printf("\n\'%s\'hasbeenopened.OpenModeis%s,FileModeis%s\n",fname,strupr(str),strupr(str1));wgetchar=1;}else{printf("\nError.\'%s\'hasn\'tbeenopened.OpenModeError.OpenModeis%s,butFileModeis%s\n",fname,strupr(str),strupr(str1));wgetchar=1;}}else{printf("\nError.FileOpenMode\'sRangeis0-2\n");wgetchar=1;}}}else{printf("\nError.\'%s\'isinopenstatus.\n",fname);wgetchar=1;}}else{printf("\nError.\'%s\'doesnotexist.\n",fname);wgetchar=1;}}voidCloseF()/*CloseFile*/{inti,k,n=0;charfname[MAXNAME];char*rtrim(char*str);/*removethetrailingblanks.*/char*ltrim(char*str);/*removetheheadingblanks.*/intExistF(char*filename);/*WhetherFileNameExist,Exist-i,NotExist-0*/intExistD(char*dirname);if(strcmp(strupr(ltrim(rtrim(dirname))),"")==0){printf("\nError.Pleaseconverttoufddirbeforeclose.\n");wgetchar=1;return;}k=ExistD(dirname);printf("\nOpenFile(s)InThisUfd:\n");/*displayopennedfile*/for(i=0;i<fcount[k];i++){if(ifopen[k][i].ifopen==1){printf("%15s",ufd[k]->ufdfile[i].fname);n++;}if((n%4==0)&&(n!=0))printf("\n");}printf("\n%dfilesopenned.\n",n);if(n==0)wgetchar=1;if(n!=0){printf("\nPleaseinputFileName:");gets(fname);ltrim(rtrim(fname));i=ExistF(fname);if(i>=0){if(ifopen[k][i].ifopen==1){ifopen[k][i].ifopen=0;ifopen[k][i].openmode=4;printf("\n\'%s\'hasbeenclosedsuccessfully.\n",fname);wgetchar=1;}else{printf("\nError.\'%s\'isinclosingstatus.\n",fname);wgetchar=1;}}else{printf("\nError.\'%s\'isnotexist.\n",fname);wgetchar=1;}}}voidReadF()/*ReadFile*/{inti,k,n=0;charfname[MAXNAME];charstr[255],str1[255],c;char*rtrim(char*str);/*removethetrailingblanks.*/char*ltrim(char*str);/*removetheheadingblanks.*/intExistF(char*filename);/*WhetherFileNameExist,Exist-i,NotExist-0*/intExistD(char*dirname);if(strcmp(strupr(ltrim(rtrim(dirname))),"")==0){printf("\nError.Pleaseconverttoufddirbeforeread.\n");wgetchar=1;return;}printf("\nCaution:Openfilefirst\n");printf("OpenedFile(s)List:\n");k=ExistD(dirname);for(i=0;i<fcount[k];i++){if(ifopen[k][i].ifopen==1)if((ifopen[k][i].openmode==0)||(ifopen[k][i].openmode==2)){printf("%15s",ufd[k]->ufdfile[i].fname);n++;}if((n%4==0)&&(n!=0))printf("\n");}printf("\n%dfilesopenned.\n",n);if(n==0)wgetchar=1;if(n!=0){printf("\nPleaseinputFileName:");gets(fname);ltrim(rtrim(fname));i=ExistF(fname);if(i>=0){if(ifopen[k][i].ifopen==1){if((ifopen[k][i].openmode==0)||(ifopen[k][i].openmode==2)){itoa(ufd[k]->ufdfile[i].fpaddr,str,10);strcpy(str1,"file");strcat(str1,str);strcpy(str,"c:\\osfile\\file\\");strcat(str,str1);fp_file=fopen(str,"rb");fseek(fp_file,0,0);printf("\nThetextis:\n\n");printf("");while(fscanf(fp_file,"%c",&c)!=EOF)if(c=='\n')printf("\n");elseprintf("%c",c);printf("\n\n%dLength.\n",ufd[k]->ufdfile[i].flength);fclose(fp_file);wgetchar=1;}else{printf("\nError.\'%s\'hasbeenopenedwithWRITEONLYmode.Itisn\'tread.\n",fname);wgetchar=1;}}else{printf("\nError.\'%s\'isinclosingstatus.Pleaseopenitbeforeread\n",fname);wgetchar=1;}}else{printf("\nError.\'%s\'doesnotexist.\n",fname);wgetchar=1;}}}voidWriteF()/*WriteFile*/{inti,k,n=0;charfname[MAXNAME];charstr[50],str1[50],a[50];char*rtrim(char*str);/*removethetrailingblanks.*/char*ltrim(char*str);/*removetheheadingblanks.*/intExistF(char*filename);/*WhetherFileNameExist,Exist-i,NotExist-0*/intExistD(char*dirname);intWriteF1();/*writefile*/if(strcmp(strupr(ltrim(rtrim(dirname))),"")==0){printf("\nError.Pleaseconverttoufddirbeforewrite.\n");wgetchar=1;return;}k=ExistD(dirname);printf("\nOpenFile(s)withwriteonlymodeorreadandwrite

溫馨提示

  • 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

評(píng)論

0/150

提交評(píng)論