操作系统课程设计_第1页
操作系统课程设计_第2页
操作系统课程设计_第3页
操作系统课程设计_第4页
操作系统课程设计_第5页
已阅读5页,还剩61页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

课程设计学生学院计算机学院专业班级12(1)班学号学生姓名吴炜文指导教师李敏1月10日目录1简朴文献系统…………文献系统一、实验目的:模拟文献管理的功效,理解多种文献的操作。二、实验内容:1、设计一种10个顾客的文献系统,每次顾客可保存10个文献,一次运行顾客能够打开5个文献2、程序采用二级文献目录(即设立主目录[MFD])和顾客文献目录(UED)。另外,为打开文献设立了运行文献目录(AFD)。3、为了便于实现,对文献的读写作了简化,在执行读写命令时,只需改读写指针,并不进行实际的读写操作。4、算法与框图:a、因系统小,文献目录的检索使用了简朴的线性搜索。b、文献保护简朴使用了三位保护码:允许读写执行、对应位为1,对应位为0,则表达不允许读写、执行。c、程序中使用的重要设计构造以下:i

主文献目录和顾客文献目录(MFD、UFD)ii打开文献目录(AFD)(即运行文献目录)规定:用高级语言编写和调试一种简朴的文献系统,模拟文献管理的工作过程。从而对多种文献操作命令的实质内容和执行过程有比较进一步的理解。规定设计一种n个顾客的文献系统,每次顾客可保存m个文献,顾客在一次运行中只能打开一种文献,对文献必须设立保护方法,且最少有Create、delete、open、close、read、write等命令。

文献系统算法的流程图以下:三、源代码及运行成果:#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. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论