代码Word格式.docx

上传人:b****2 文档编号:4699268 上传时间:2023-05-03 格式:DOCX 页数:46 大小:48.56KB
下载 相关 举报
代码Word格式.docx_第1页
第1页 / 共46页
代码Word格式.docx_第2页
第2页 / 共46页
代码Word格式.docx_第3页
第3页 / 共46页
代码Word格式.docx_第4页
第4页 / 共46页
代码Word格式.docx_第5页
第5页 / 共46页
代码Word格式.docx_第6页
第6页 / 共46页
代码Word格式.docx_第7页
第7页 / 共46页
代码Word格式.docx_第8页
第8页 / 共46页
代码Word格式.docx_第9页
第9页 / 共46页
代码Word格式.docx_第10页
第10页 / 共46页
代码Word格式.docx_第11页
第11页 / 共46页
代码Word格式.docx_第12页
第12页 / 共46页
代码Word格式.docx_第13页
第13页 / 共46页
代码Word格式.docx_第14页
第14页 / 共46页
代码Word格式.docx_第15页
第15页 / 共46页
代码Word格式.docx_第16页
第16页 / 共46页
代码Word格式.docx_第17页
第17页 / 共46页
代码Word格式.docx_第18页
第18页 / 共46页
代码Word格式.docx_第19页
第19页 / 共46页
代码Word格式.docx_第20页
第20页 / 共46页
亲,该文档总共46页,到这儿已超出免费预览范围,如果喜欢就下载吧!
下载资源
资源描述

代码Word格式.docx

《代码Word格式.docx》由会员分享,可在线阅读,更多相关《代码Word格式.docx(46页珍藏版)》请在冰点文库上搜索。

代码Word格式.docx

OSFILEufdfile[MAXCHILD];

/*ufd拥有的文件*/

}OSUFD;

typedefstruct/*OSUFD'

LOGIN结构*/

charufdpword[8];

/*ufd密码*/

}OSUFD_LOGIN;

typedefstruct/*打开方式*/

{intifopen;

/*0-关闭,1-打开*/

intopenmode;

/*0-只读,1-只写,2-读写,3-初始化*/

}OSUFD_OPENMODE;

OSUFD*ufd[MAXCHILD];

/*ufdandufd拥有的文件*/

OSUFD_LOGINufd_lp;

intucount=0;

/*mfd拥有的的ufds数量*/

intfcount[MAXCHILD];

/*ufd的文件数量*/

intloginsuc=0;

/*登陆是否成功*/

charusername[MAXNAME];

/*记录登陆者姓名*/

chardirname[MAXNAME];

/*记录当前目录*/

intfpaddrno[MAX];

/*记录文件物理地址数据*/

OSUFD_OPENMODEifopen[MAXCHILD][MAXCHILD];

/*记录文件开关*/

intwgetchar;

/*是否调用getchar()函数*/

FILE*fp_mfd,*fp_ufd,*fp_file_p,*fp_file;

voidmain()

{inti,j,choice1;

charchoice[50];

/*选择要进行的操作:

dir,创建,删除,打开,修改,读,写*/

intchoiceend=1;

/*选择是否结束*/

char*rtrim(char*str);

/*清除文字间的空格*/

char*ltrim(char*str);

/*移除头部空格*/

voidLoginF();

/*登陆文件系统*/

voidDirF();

/*DirFileSystem*/

voidCdF();

/*ChangeDir*/

voidCreateF();

/*创建文件*/

voidDeleteF();

/*删除文件*/

voidModifyFM();

/*修改文件模式*/

voidOpenF();

/*打开文件*/

voidCloseF();

/*关闭文件*/

voidReadF();

/*读文件*/

voidWriteF();

/*写文件*/

voidQuitF();

/*离开文件系统*/

voidhelp();

/*帮助*/

if((fp_mfd=fopen("

c:

\\osfile\\mfd"

"

rb"

))==NULL)

{fp_mfd=fopen("

wb"

);

fclose(fp_mfd);

}

for(i=0;

i<

MAX;

i++)fpaddrno[i]=0;

textattr(BLACK*16|WHITE);

clrscr();

/*清屏*/

LoginF();

/*用户登陆*/

if(loginsuc==1)/*登陆成功*/

{while

(1)

{wgetchar=0;

if(choiceend==1)

{printf("

\n\nC:

\\%s>

"

strupr(dirname));

}//strupr将所有小写字母转换成大写

elseprintf("

Badcommandorfilename.\nC:

strupr(username));

gets(choice);

strcpy(choice,ltrim(rtrim(strlwr(choice))));

//strlwr将所有大写字母转换成小写

if(strcmp(choice,"

dir"

)==0)choice1=1;

elseif(strcmp(choice,"

creat"

)==0)choice1=2;

delete"

)==0)choice1=3;

attrib"

)==0)choice1=4;

open"

)==0)choice1=5;

close"

)==0)choice1=6;

read"

)==0)choice1=7;

modify"

)==0)choice1=8;

exit"

)==0)choice1=9;

cls"

)==0)choice1=10;

cd"

)==0)choice1=11;

help"

)==0)choice1=20;

elsechoice1=12;

switch(choice1)

{case1:

DirF();

choiceend=1;

break;

case2:

CreateF();

if(!

wgetchar)getchar();

case3:

DeleteF();

wgetchar)getchar();

case4:

ModifyFM();

case5:

OpenF();

if(!

case6:

CloseF();

case7:

ReadF();

case8:

WriteF();

case9:

printf("

\nYouhaveexitedthissystem."

QuitF();

exit(0);

case10:

case11:

CdF();

case20:

help();

default:

choiceend=0;

\nAccessdenied."

voidhelp(void)

{

\nTheCommandList\n"

\nCdAttribCreatModifyReadOpenClsDeleteExitClose\n"

char*rtrim(char*str)/*removethetrailingblanks.*/

{intn=strlen(str)-1;

while(n>

=0)

{if(*(str+n)!

='

'

{*(str+n+1)='

\0'

;

elsen--;

if(n<

0)str[0]='

returnstr;

char*ltrim(char*str)/*removetheheadingblanks.*/

{char*rtrim(char*str);

strrev(str);

//将所有字母反向排列

rtrim(str);

voidLoginF()/*LOGINFileSystem*/

{charloginame[MAXNAME],loginpw[9],logincpw[9],str[50];

inti,j,flag=1;

chara[25];

intfindout;

/*loginusernotexist*/

/*removethetrailingblanks.*/

/*removetheheadingblanks.*/

voidInputPW(char*password);

/*inputpassword,use'

*'

replace*/

voidSetPANo(intRorW);

/*Setphysicaladdressnum*/

while

(1)

{findout=0;

\n\nLoginName:

gets(loginame);

ltrim(rtrim(loginame));

fp_mfd=fopen("

\\osfile\\"

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);

if(findout==1)/*userexist*/

LoginPassword:

InputPW(loginpw);

if(strcmp(loginpw,logincpw)==0)

{strcpy(username,strupr(loginame));

strcpy(dirname,username);

for(j=0;

j++)

{strcpy(str,"

strcat(str,ufd_lp.ufdname);

//strcat字符串连接函数

ufd[j]=(OSUFD*)malloc(sizeof(OSUFD));

strcpy(ufd[j]->

ufdname,strupr(ufd_lp.ufdname));

fp_ufd=fopen(str,"

fcount[j]=0;

ufd[j]->

ufdfile[i],sizeof(OSFILE),1,fp_ufd)!

i++,fcount[j]++)

{ifopen[j][i].ifopen=0;

ifopen[j][i].openmode=4;

fclose(fp_ufd);

ucount=j;

SetPANo(0);

\n\nLoginsuccessful!

WelcometothisFileSystem\n\n"

loginsuc=1;

return;

else

\n\n"

flag=1;

while(flag)

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;

NewPassword(<

=8):

/*inputnewpassword,use'

\nConfirmPassword(<

InputPW(logincpw);

{strcpy(ufd_lp.ufdname,strupr(loginame));

strcpy(ufd_lp.ufdpword,loginpw);

ab"

fwrite(&

ufd_lp,sizeof(OSUFD_LOGIN),1,fp_mfd);

strcpy(username,strupr(loginame));

strcpy(dirname,loginame);

strcpy(str,"

strcat(str,username);

if((fp_ufd=fopen(str,"

{fp_ufd=fopen(str,"

\n\nLoginSuccessful!

WelcometothisSystem\n\n"

voidSetPANo(intRorW)/*Setphysicaladdressnum,0-read,1-write*/

{inti,j;

if(RorW==0)

{if((fp_file_p=fopen("

\\osfile\\file\\file_p"

{fp_file_p=fopen("

fclose(fp_file_p);

fp_file_p=fopen("

j,sizeof(int),1,fp_file_p)!

fpaddrno[j]=1;

/*for(i=1;

if((i%13)==0)fpaddrno[i]=1;

if((i%13)==0)fpaddrno[i]=0;

if(fpaddrno[i]==1)

i,sizeof(int),1,fp_file_p);

voidInputPW(char*password)/*inputpassword,use'

{intj;

j<

=7;

{password[j]=getch();

if((int)(password[j])!

=13)

{if((int)(password[j])!

=8)

putchar('

{if(j>

0)

{j--;

j--;

\b'

elsej--;

{password[j]='

password[j]='

voidDirF()/*DirFileSystem*/

{inti,j,count=0;

charsfmode[25],sfpaddr[25],str[25];

intExistD(char*dirname);

/*WhetherDirNameExist,Exist-i,NotExist-0*/

if(strcmp(strupr(ltrim(rtrim(dirname))),"

)!

dir\n"

dirname);

\n%14s%16s%14s%10s%18s\n"

FileName"

FileAddress"

FileLength"

Type"

FileMode"

j=ExistD(dirname);

fcount[j];

{if((i%16==0)&

&

(i!

=0))

\nPressanykeytocontinue.."

getch();

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"

ufdfile[i].fmode==2)strcpy(sfmode,"

ReadAndWrite"

elsestrcpy(sfmode,"

Protect"

%14s%16s%14d%10s%18s\n"

ufd[j]->

ufdfile[i].fname,sfpaddr,ufd[j]->

ufdfile[i].flength,"

<

FILE>

sfmode);

\n%3dfile(s)\n"

fcount[j]);

\\>

\n%14s%18s%8s\n"

DirName"

OwnFileCount"

ucount;

\nPressanykeytocontinue..."

%14s%18d%8s\n"

ufd[i]->

ufdname,fcount[i],"

UFD>

count=count+fcount[i];

\n%3ddir(s),%5dfile(s)\n"

ucount,count);

intExistD(char*dirname)/*WhetherDirNameExist,Exist-i,NotExist-0*/

{inti;

intexist=0;

if(strcmp(strupr(ufd[i]->

ufdname),strupr(dirname))==0)

{exist=1;

if(exist)return(i);

elsereturn(-1);

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 工程科技 > 能源化工

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2