模拟一个简单二级文件管理系统Word文件下载.docx

上传人:b****1 文档编号:5929489 上传时间:2023-05-05 格式:DOCX 页数:30 大小:190.17KB
下载 相关 举报
模拟一个简单二级文件管理系统Word文件下载.docx_第1页
第1页 / 共30页
模拟一个简单二级文件管理系统Word文件下载.docx_第2页
第2页 / 共30页
模拟一个简单二级文件管理系统Word文件下载.docx_第3页
第3页 / 共30页
模拟一个简单二级文件管理系统Word文件下载.docx_第4页
第4页 / 共30页
模拟一个简单二级文件管理系统Word文件下载.docx_第5页
第5页 / 共30页
模拟一个简单二级文件管理系统Word文件下载.docx_第6页
第6页 / 共30页
模拟一个简单二级文件管理系统Word文件下载.docx_第7页
第7页 / 共30页
模拟一个简单二级文件管理系统Word文件下载.docx_第8页
第8页 / 共30页
模拟一个简单二级文件管理系统Word文件下载.docx_第9页
第9页 / 共30页
模拟一个简单二级文件管理系统Word文件下载.docx_第10页
第10页 / 共30页
模拟一个简单二级文件管理系统Word文件下载.docx_第11页
第11页 / 共30页
模拟一个简单二级文件管理系统Word文件下载.docx_第12页
第12页 / 共30页
模拟一个简单二级文件管理系统Word文件下载.docx_第13页
第13页 / 共30页
模拟一个简单二级文件管理系统Word文件下载.docx_第14页
第14页 / 共30页
模拟一个简单二级文件管理系统Word文件下载.docx_第15页
第15页 / 共30页
模拟一个简单二级文件管理系统Word文件下载.docx_第16页
第16页 / 共30页
模拟一个简单二级文件管理系统Word文件下载.docx_第17页
第17页 / 共30页
模拟一个简单二级文件管理系统Word文件下载.docx_第18页
第18页 / 共30页
模拟一个简单二级文件管理系统Word文件下载.docx_第19页
第19页 / 共30页
模拟一个简单二级文件管理系统Word文件下载.docx_第20页
第20页 / 共30页
亲,该文档总共30页,到这儿已超出免费预览范围,如果喜欢就下载吧!
下载资源
资源描述

模拟一个简单二级文件管理系统Word文件下载.docx

《模拟一个简单二级文件管理系统Word文件下载.docx》由会员分享,可在线阅读,更多相关《模拟一个简单二级文件管理系统Word文件下载.docx(30页珍藏版)》请在冰点文库上搜索。

模拟一个简单二级文件管理系统Word文件下载.docx

uname[]char,用户名、upassword[]char,用户密码;

userfile结构体用户文件数据结构:

uname[]char,用户名、ufile[]file,用户拥有的文件数组.

代码:

#include<

stdio.h>

stdlib.h>

conio.h>

time.h>

string.h>

#defineMaxUser100//定义最大MDF主目录文件

#defineMaxDisk512*1024//模拟最大磁盘空间

#definecommandAmount12//对文件操作的指令数

//存储空间管理有关结构体和变量

chardisk[MaxDisk];

//模拟512K的磁盘存储空间

typedefstructdistTable//磁盘块结构体

{

intmaxlength;

intstart;

intuseFlag;

distTable*next;

}diskNode;

diskNode*diskHead;

structfileTable//文件块结构体

charfileName[10];

intstrat;

//文件在磁盘存储空间的起始地址

intlength;

//文件内容长度

//文件的最大长度

charfileKind[3];

//文件的属性——读写方式

structtm*timeinfo;

boolopenFlag;

//判断是否有进程打开了该文件

//fileTable*next;

};

//两级目录结构体

typedefstructuser_file_directory//用户文件目录文件UFD

//charfileName[10];

fileTable*file;

user_file_directory*next;

}UFD;

//UFD*headFile;

typedefstructmaster_file_directory//主文件目录MFD

charuserName[10];

charpassword[10];

UFD*user;

}MFD;

MFDuserTable[MaxUser];

intused=0;

//定义MFD目录中用已有的用户数

//文件管理

voidfileCreate(charfileName[],intlength,charfileKind[]);

//创建文件

voidfileWrite(charfileName[]);

//写文件

voidfileCat(charfileName[]);

//读文件

voidfileRen(charfileName[],charrename[]);

//重命名文件

voidfileFine(charfileName[]);

//查询文件

voidfileDir(charUserName[]);

//显示某一用户的所有文件

voidfileClose(charfileName[]);

//关闭已打开的文件

voidfileDel(charfileName[]);

//删除文件

voidchmod(charfileName[],charkind[]);

//修改文件的读写方式

intrequestDist(int&

startPostion,intmaxLength);

//磁盘分配查询

voidinitDisk();

//初始化磁盘

voidfreeDisk(intstartPostion);

//磁盘空间释放

voiddiskShow();

//显示磁盘使用情况

//用户管理

voiduserCreate();

intlogin();

intuserID=-1;

//用户登录的ID号,值为-1时表示没有用户登录

intmain()

charorder[commandAmount][10];

strcpy(order[0],"

create"

);

strcpy(order[1],"

rm"

strcpy(order[2],"

cat"

strcpy(order[3],"

write"

strcpy(order[4],"

fine"

strcpy(order[5],"

chmod"

strcpy(order[6],"

ren"

strcpy(order[7],"

dir"

strcpy(order[8],"

close"

strcpy(order[9],"

return"

strcpy(order[10],"

exit"

strcpy(order[11],"

df"

charcommand[50],command_str1[10],command_str2[10],command_str3[5],command_str4[3];

inti,k,j;

initDisk();

for(i=0;

i<

MaxUser;

i++)//初始化用户UFD目录文件的头指针

{

userTable[i].user=(UFD*)malloc(sizeof(UFD));

userTable[i].user->

next=NULL;

}

while

(1)

printf("

********************************************\n"

1、Creatuser\n"

2、login\n"

Pleasechoocethefunctionkey:

>

"

intchoice;

scanf("

%d"

&

choice);

if(choice==1)userCreate();

elseif(choice==2)userID=login();

elseprintf("

您的输入有误,请重新选择\n"

while(userID!

=-1)

fflush(stdin);

———————————————————————————————————————\n"

create-创建格式:

createa11000rw,将创建名为a1,长度为1000字节可读可写的文件\n"

rm-删除格式:

rma1,将删除名为a1的文件\n"

cat-查看文件内容格式:

cata1,显示a1的内容\n"

write-写入格式:

writea1\n"

fine-查询格式:

finea1,将显示文件a1的属性\n"

chmod-修改格式:

chmoda1r,将文件a1的权限改为只读方式\n"

ren-重命名格式:

rena1b1,将a1改名为b1\n"

dir-显示文件格式:

diraaa,将显示aaa用户的所有文件\n"

df-显示磁盘空间使用情况格式:

df\n"

close-关闭文件格式:

closea1,将关闭文件a1\n"

return-退出用户,返回登录界面\n"

exit-退出程序\n"

————————————————————————————————————————\n"

pleaseimputyourcommand:

gets(command);

intselect;

command[i]!

='

'

&

\0'

;

i++)//command_str1字符串存储命令的操作类型

command_str1[i]=command[i];

k=i;

command_str1[k]='

commandAmount;

i++)

if(!

strcmp(command_str1,order[i]))

select=i;

break;

if(i==commandAmount)

您输入的命令有误,请重新输入\n"

continue;

for(i=k+1,k=0;

i++,k++)//commmand_str2字符串存储文件名或用户名

command_str2[k]=command[i];

command_str2[k]='

switch(select)

case0:

for(i=k+1,k=0;

i++,k++)

command_str3[k]=command[i];

command_str3[k]='

j=1;

length=0;

//初始化文件长度

for(i=strlen(command_str3)-1;

i>

=0;

i--)//把字符串转换为十进制

length+=(command_str3[i]-48)*j;

j*=10;

command_str4[k]=command[i];

command_str4[k]='

fileCreate(command_str2,length,command_str4);

break;

case1:

fileDel(command_str2);

case2:

fileCat(command_str2);

case3:

fileWrite(command_str2);

case4:

fileFine(command_str2);

case5:

chmod(command_str2,command_str3);

case6:

fileRen(command_str2,command_str3);

case7:

fileDir(command_str2);

case8:

fileClose(command_str2);

case9:

UFD*p;

for(p=userTable[userID].user->

next;

p!

=NULL;

p=p->

next)//退出用户之前关闭所有打的文件

if(p->

file->

openFlag)

p->

openFlag=false;

system("

cls"

userID=-1;

case10:

exit(0);

case11:

diskShow();

return0;

}

voiduserCreate()

charc;

inti;

if(used<

MaxUser)

请输入用户名:

c=getch();

if(c==13)break;

else

userName[i]=c;

%c"

c);

userName[i]='

used;

strcmp(userTable[i].userName,userName))

\n"

该用户名已存在,创建用户失败\n"

pause"

return;

strcpy(userTable[used].userName,userName);

请输入密码:

userTable[used].password[i]=c;

*"

userTable[userID].password[i]='

创建用户成功\n"

used++;

创建用户失败,用户已达到上限\n"

intlogin()

charname[10],psw[10];

inti,times;

请输入用户名:

name[i]=c;

name[i]='

strcmp(userTable[i].userName,name))

if(i==used)

\n您输入的用户名不存在\n"

return-1;

for(times=0;

times<

3;

times++)

memset(psw,'

sizeof(psw));

\n请输入密码:

psw[i]=c;

strcmp(psw,userTable[i].password))

用户登录成功\n"

您输入的密码错误,您还有%d次输入机会\n"

2-times);

if(times==2)exit(0);

elsebreak;

returni;

voidinitDisk()

diskHead=(diskNode*)malloc(sizeof(diskNode));

diskHead->

maxlength=MaxDisk;

useFlag=0;

start=0;

startPostion,intmaxLength)

intflag=0;

//标记是否分配成功

diskNode*p,*q,*temp;

p=diskHead;

while(p)

useFlag==0&

p->

maxlength>

maxLength)

startPostion=p->

start;

q=(diskNode*)malloc(sizeof(diskNode));

q->

start=p->

maxlength=maxLength;

useFlag=1;

start+maxLength;

maxlength=p->

maxlength-maxLength;

flag=1;

temp=p;

if(diskHead->

next==NULL)diskHead->

next=q;

while(temp->

next)temp=temp->

temp->

p=p->

returnflag;

voidfileCreate(charfileName[],intlength,charfileKind[])

//inti,j;

time_trawtime;

intstartPos;

UFD*fileNode,*p;

next)

strcmp(p->

fileName,fileName))

文件重名,创建文件失败\n"

if(requestDist(startPos,length))

fileNode=(UFD*)malloc(sizeof(UFD));

fileNode->

file=(fileTable*)malloc(sizeof(fileTable));

//这一步必不可少,因为fileNode里面的指针也需要申请地址,否则fileNode->

file指向会出错

strcpy(fileNode->

fileName,fileName);

fileKind,fileKind);

maxlength=length;

strat=startPos;

time(&

rawtime);

timeinfo=localtime(&

if(userTable[userID].user->

next==NULL)

userTable[userID].user->

next=fileNode;

p=userTable[userID].user->

while(p->

next)p=p->

创建文件成功\n"

磁盘空间已满或所创建文件超出磁盘空闲容量,磁盘空间分配失败\n"

voidfreeDisk(intstartPostion)

diskNode*p;

for(p=diskHead;

p=p

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

当前位置:首页 > IT计算机 > 电脑基础知识

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

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