主题:关于文件管理的,小妹不知道怎么改,帮帮!!
模拟实现采用二级文件目录结构,第一级为主目录文件MFD,第二级为用户文件。目录文件UFD。
(1) 设计一个有m个用户的文件系统,每个用户最多可保存一个文件;
(2) 规定用户在一次运行中只能打开K个文件;
(3) 系统能检查键入命令的正确性,出错时应能显示出错原因;
(4) 对文件应能设置保护措施,如只能执行,允许读,允许写等;
(5) 对文件的操作设计提供一套文件操作:
CREATE 建立文件
DELETE 删除文件
OPEN 打开文件
CLOSE 关闭文件
READ 读写文件
WRITE 写文件
[color=FF00FF][size=3]下面的程序运行有错;
可我不知道怎么改;[/size][/color]
proram fsystem(input,output);
label 10;
type
y=string[10]
links=^datas;
data=record
filename:y;
pcode:links;
length:integer;
end;
link=^dataf;
dataf=recod
ue4rname:y;
next:links;
end;
linkf=^dataf;
dataf=record
filename:y;
opening:integer;
next:linkt;
end;
var
mfd:array[1..5]of linkf;
pl,ql:linkf;
ufd.p2,q2:link;
x:y;
afd,p3,q3:linkt;
t:boolean;
r,l,I,l,k,n,s,m,j:integer;
procedure print;
begin
for I:=1to n do
begin
writeln(‘mfd-‘,mfd[I]^.username);
p2:=mfd[I]^next;
while p2<>nill do
begin
writeln(‘ufd-filename );
writeln(p2^.filename:6,’-‘:6,p2^.pcode:6,p2^length:6);
p2:=p2^next;
end;
end;
if i1<>0 then
begin
p3:=afd;
while p3<>nil do
begin
writeln(‘afd-filename opening’);
writeln(p3^.filename:6,’-‘:6,p3^. opening:6);
p3:=p3^next;
end;
end;
end
procedure pcreate;
begin
writeln(‘create name=’);
readln(x);
q2:=ufdd;
while(q2^.filename<>x)and(q2^.next<>nil)do
q2:=q2^.next;
if q2^.next=nil then
begin
new(p2);
q2.next:=p2;
p2^.filename:=x;
write(‘create code=’);
readln(m);
p2^.fpcode:=m;
write(create length=’);
readln(s);
p2^.length:=s;
p2^.next:=nil;
writeln(‘create finish’);
print;
endelse writeln(‘file has already been created’);
end;
procedure popen;
begin
p2:=ufd;
write(‘input filename=’);
readln(x);
while(p2^.filename<>x)and(p2^.next<>nil)do
p2:=p2^.next;
if p2^.filename=x then
begin
if i1<>0 then
begin
q3:=q3^.next;
end;
end;
if( q3^.filename=x )then
writeln(‘the file is on the afd’)
else
begin
new(p3);
if i1=0 then afd:=p3;
else q3^.next:=p3;
i1:=i1+1;
p3^.filename:=x;
p3^.opening:=i1;
p3^.next:=nil;
writeln(‘the file has been opend ,file number=’.i1);
writeln;
writeln;
end;
end;
else write(‘error);
writeln;
print;
end;
procedure pcreate;
begin
write(‘the file name to be deleted=’);
readln(x);
writeln;
p3:=afd;q3:afd;
if p3^.filename<>x then
begin
q3:=p3;
p3:=p3^.next;
end;
if p3^.filename=x then
begin
q3^.next:=p3^.next;
dispose(p3);
end;
p2:=ufd;q2:ufd;
if p2^.filename<>x then
begin
while(p2^.filename<>x)and(p2^.next<>nil)do
being
q2:=p2;
p2:=p2^.next;
end;
if p2^.filename=xs then
begin
q2^.next:=p2^.next;
dispose(p2);
writeln(‘the file is deleted’)
end;
else
begin
ufd:=p2^.next;
dispose(p2);
writeln(‘the file is deleted’)
end;
print;
end;
procedure pclose;
var
j:integer;
begin
write(‘input close filename=’);
readln(x);q3:=afd;p3:=q3;j:=0;
while(q3^.filename<>x)and(q3^.next<>nil)do
being
p3:=q3;
q3:=p3^.next;
end;
if(q3^.next<>nil)or(q3^.filename<>x)then
begin
p3^.next:=q3^.next;
dispose(q3);
writeln(‘end of close’);
p3:=afd;
while(p3^.next<>nil)do
begin
j:=j+1;p3:=p3^.next;
end;
if j=0 then i1:=0;
writeln(‘afd file number=’.I);while
writeln;
end
else writeln(‘not retionnal’);
print;
end;
procedure pbye;
begin
p2:ufd;
writeln(‘ufd---filename ---pocde---length’);
while p2<>nil do
begin
write(p2^.filename:13);
write(p2^.pocde:7,p2^.length:10);
writeln;
p2:=p2^.next;
end;
write(‘the end of imiate ‘);
writeln(‘1991.5’);
t:=ture;
end;
begin(*-----------------------main program---------------------------*)
write(‘user number n=’);
readln(n);
for i1:=1 to n do
begin
write(‘uer mfd filename x’,I:22,’=’:=2);
readln(x);
new (mfd[I]);
p1:=mfd[I];
p1:=mfd[I];
p1^.username:=x;
p1^.next:=nil;
write(‘input(‘,I:2,’)’);
write(‘one uer file numbers k=’);
readln(k);
new(p2);
for j:=1 to k do
begin
write(‘input ufd--------name=’);
readln(x);
p2^.length;=s;
p2^.next:=nil;
ufd:=p2; new(p2);
ufd^.next:=p2;
end;
print;
writeln(‘input uer name you wantto opearate’);
readln(x);I:=1;
whilex<>mfd[I]^.uername do
begin
if i>=n then
begin
writeln(‘not found user mfd filename’);
writeln(‘input again mfd filename’);
goto 10
end
else
i:=i+1;
end;
ufd:=mfd[I]^.next;
t:=fale; i1:=0;
while t<>true do
begin
writeln(‘--------------------------------------------------------’);
writeln(‘ 1---create 2---open ’);
writeln(‘ 3---delete 4---close ’);
writeln(‘ 5---read 6--- write ’);
writeln(‘ 7---end ’);
writeln(‘---------------------------------------------------------’);
readln(s);
case s of
1:pcreate;
2:popen;
3:pdelete;
4:pclose;
5:pread;
6:pwrite;
7:pbye;
end;
end.
(1) 设计一个有m个用户的文件系统,每个用户最多可保存一个文件;
(2) 规定用户在一次运行中只能打开K个文件;
(3) 系统能检查键入命令的正确性,出错时应能显示出错原因;
(4) 对文件应能设置保护措施,如只能执行,允许读,允许写等;
(5) 对文件的操作设计提供一套文件操作:
CREATE 建立文件
DELETE 删除文件
OPEN 打开文件
CLOSE 关闭文件
READ 读写文件
WRITE 写文件
[color=FF00FF][size=3]下面的程序运行有错;
可我不知道怎么改;[/size][/color]
proram fsystem(input,output);
label 10;
type
y=string[10]
links=^datas;
data=record
filename:y;
pcode:links;
length:integer;
end;
link=^dataf;
dataf=recod
ue4rname:y;
next:links;
end;
linkf=^dataf;
dataf=record
filename:y;
opening:integer;
next:linkt;
end;
var
mfd:array[1..5]of linkf;
pl,ql:linkf;
ufd.p2,q2:link;
x:y;
afd,p3,q3:linkt;
t:boolean;
r,l,I,l,k,n,s,m,j:integer;
procedure print;
begin
for I:=1to n do
begin
writeln(‘mfd-‘,mfd[I]^.username);
p2:=mfd[I]^next;
while p2<>nill do
begin
writeln(‘ufd-filename );
writeln(p2^.filename:6,’-‘:6,p2^.pcode:6,p2^length:6);
p2:=p2^next;
end;
end;
if i1<>0 then
begin
p3:=afd;
while p3<>nil do
begin
writeln(‘afd-filename opening’);
writeln(p3^.filename:6,’-‘:6,p3^. opening:6);
p3:=p3^next;
end;
end;
end
procedure pcreate;
begin
writeln(‘create name=’);
readln(x);
q2:=ufdd;
while(q2^.filename<>x)and(q2^.next<>nil)do
q2:=q2^.next;
if q2^.next=nil then
begin
new(p2);
q2.next:=p2;
p2^.filename:=x;
write(‘create code=’);
readln(m);
p2^.fpcode:=m;
write(create length=’);
readln(s);
p2^.length:=s;
p2^.next:=nil;
writeln(‘create finish’);
print;
endelse writeln(‘file has already been created’);
end;
procedure popen;
begin
p2:=ufd;
write(‘input filename=’);
readln(x);
while(p2^.filename<>x)and(p2^.next<>nil)do
p2:=p2^.next;
if p2^.filename=x then
begin
if i1<>0 then
begin
q3:=q3^.next;
end;
end;
if( q3^.filename=x )then
writeln(‘the file is on the afd’)
else
begin
new(p3);
if i1=0 then afd:=p3;
else q3^.next:=p3;
i1:=i1+1;
p3^.filename:=x;
p3^.opening:=i1;
p3^.next:=nil;
writeln(‘the file has been opend ,file number=’.i1);
writeln;
writeln;
end;
end;
else write(‘error);
writeln;
print;
end;
procedure pcreate;
begin
write(‘the file name to be deleted=’);
readln(x);
writeln;
p3:=afd;q3:afd;
if p3^.filename<>x then
begin
q3:=p3;
p3:=p3^.next;
end;
if p3^.filename=x then
begin
q3^.next:=p3^.next;
dispose(p3);
end;
p2:=ufd;q2:ufd;
if p2^.filename<>x then
begin
while(p2^.filename<>x)and(p2^.next<>nil)do
being
q2:=p2;
p2:=p2^.next;
end;
if p2^.filename=xs then
begin
q2^.next:=p2^.next;
dispose(p2);
writeln(‘the file is deleted’)
end;
else
begin
ufd:=p2^.next;
dispose(p2);
writeln(‘the file is deleted’)
end;
print;
end;
procedure pclose;
var
j:integer;
begin
write(‘input close filename=’);
readln(x);q3:=afd;p3:=q3;j:=0;
while(q3^.filename<>x)and(q3^.next<>nil)do
being
p3:=q3;
q3:=p3^.next;
end;
if(q3^.next<>nil)or(q3^.filename<>x)then
begin
p3^.next:=q3^.next;
dispose(q3);
writeln(‘end of close’);
p3:=afd;
while(p3^.next<>nil)do
begin
j:=j+1;p3:=p3^.next;
end;
if j=0 then i1:=0;
writeln(‘afd file number=’.I);while
writeln;
end
else writeln(‘not retionnal’);
print;
end;
procedure pbye;
begin
p2:ufd;
writeln(‘ufd---filename ---pocde---length’);
while p2<>nil do
begin
write(p2^.filename:13);
write(p2^.pocde:7,p2^.length:10);
writeln;
p2:=p2^.next;
end;
write(‘the end of imiate ‘);
writeln(‘1991.5’);
t:=ture;
end;
begin(*-----------------------main program---------------------------*)
write(‘user number n=’);
readln(n);
for i1:=1 to n do
begin
write(‘uer mfd filename x’,I:22,’=’:=2);
readln(x);
new (mfd[I]);
p1:=mfd[I];
p1:=mfd[I];
p1^.username:=x;
p1^.next:=nil;
write(‘input(‘,I:2,’)’);
write(‘one uer file numbers k=’);
readln(k);
new(p2);
for j:=1 to k do
begin
write(‘input ufd--------name=’);
readln(x);
p2^.length;=s;
p2^.next:=nil;
ufd:=p2; new(p2);
ufd^.next:=p2;
end;
print;
writeln(‘input uer name you wantto opearate’);
readln(x);I:=1;
whilex<>mfd[I]^.uername do
begin
if i>=n then
begin
writeln(‘not found user mfd filename’);
writeln(‘input again mfd filename’);
goto 10
end
else
i:=i+1;
end;
ufd:=mfd[I]^.next;
t:=fale; i1:=0;
while t<>true do
begin
writeln(‘--------------------------------------------------------’);
writeln(‘ 1---create 2---open ’);
writeln(‘ 3---delete 4---close ’);
writeln(‘ 5---read 6--- write ’);
writeln(‘ 7---end ’);
writeln(‘---------------------------------------------------------’);
readln(s);
case s of
1:pcreate;
2:popen;
3:pdelete;
4:pclose;
5:pread;
6:pwrite;
7:pbye;
end;
end.