?? main.cpp
字號:
#include"file.h"
extern void write(char *tmpname,int tmplen);
extern void cover(char *tmpname,int tmplen);
extern void insert(char *tmpname,int insertpoint);
//文件結構數組
fileinfo file[FILENUM];
int filenum;//文件數量
int FAT[DISC],blankspace;//FAT表和剩余空間
int main(int argc,char *argv[])
{
char tmpname[FILENAMELEN];
int tmplen;//要寫入文件長度
int order;//命令
filenum=0;
//初始化FAT表
for(int i=0;i<DISC;i++)
FAT[i]=0;
FAT[0]=FDF;
FAT[1]=FFF;
blankspace=98;
while(1)
{
cout<<"Select the operation:"<<endl<<"1 for writing"<<endl<<"2 for inserting"<<endl;
cout<<"other numbers to quit"<<endl;
cin>>order;
switch(order)
{
case 1: cout<<"Input the name of the file"<<endl;
cin>>tmpname;
cout<<"Input the length of the file"<<endl;
cin>>tmplen;
//判斷是否有重名文件
for(i=0;i<filenum;i++)
if(strcmp(file[i].filename,tmpname)==0)
{ //若同意覆蓋,則進入覆蓋函數,否則進行下一次操作
cout<<"Cover the quondam file?(y/n)"<<endl;
char tmpch=getchar();
if(tmpch == 'y' || tmpch == 'Y')
{
cover(tmpname,tmplen);
break;
}
else break;
}
//若無重名文件則寫入,寫入前判斷是否有足夠空間
if(tmplen>blankspace)
{
cout<<"not enough space!"<<endl;
break;
}
if(i==filenum) write(tmpname,tmplen);
break;
case 2: cout<<"Input the name of the file"<<endl;
cin>>tmpname;
int insertpoint;
cout<<"Input the breakpoint of the file"<<endl;
cin>>insertpoint;
for(i=0;i<filenum;i++)
if(strcmp(file[i].filename,tmpname)==0)
break;
if(i==filenum)
{
cout<<"There isn't the file with this name"<<endl;
break;
}
//若無空間,則不插入
if(blankspace==0)
{
cout<<"not enough space!"<<endl;
break;
}
insert(tmpname,insertpoint);
break;
default :break;
}
//詢問是否繼續輸入命令
cout <<endl<<endl<<endl<< "Go on?(y/n)"<<endl;
fgets(tmpname, sizeof(tmpname), stdin);
if(*tmpname != 'y' && *tmpname != 'Y')
return 0;
putchar('\n');
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -