欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 财经 > 产业 > wwwwww

wwwwww

2025/6/24 5:40:47 来源:https://blog.csdn.net/derive_magic/article/details/148850335  浏览:    关键词:wwwwww

#inculde<string.h>
#include<stdlib.h>
#include<iostream>
using namespace std;

//孩子节点链表结构
typedef struct Childnode
{
    int childIndex;
    struct Childnode *next;    
}Childnode;

//文件目录节点 
typedef struct
{
    char name[10000];
    int parentIndex;
    Childnode* children;//该结点的孩子头指针 
    int flag;//文件为0,文件夹为1 
    char content[10000];
    int is_open;//1为文件已经打开,0为文件未打开      
}Filenode;

//全局变量
Filenode node[10000];//存储节点的数组 
int nodecount=0;//节点数量 
int curdir=0;//当前目录下标 

//初始化系统 
void initsystem()
{
    strcpy(node[0].name,"root");
    node[0].parentIndex=-1;
    node[0].children=NULL;
    node[0].flag=1;
    node[0].content[0]="\0";
    node[0].is_open=0;
    
    nodecount=1;
    curdir=0; 

//查找子节点 
int findChild(int i,char *name,int flag)
{
    Childnode* cur=node[parentIndex].children;
    while(cur!=NULL){
        int childIndex=cur->childIndex;
        if(strcmp(node[childIndex].name,name)==0&&node[childIndex].flag==flag){
            return childIndex;
        }
        cur=cur->next;
    }
    return -1;//未找到 
}
//创建节点
int createnode(char* name,int i,int flag) 
{
    if(nodecount>=10000){
        cout<<"ERROR:createnode";
        return -1;
    }
    int index=findchild(i,name,flag);
    if(index!=-1){
        if(flag==1)
            printf("ERROR:directory %s already exists",name);
        else
            printf("ERROR:file %s already exists",name);
        return -1
    }
    
    //对新结点初始化
    int newIndex=nodecount++;
    node[newIndex].parentIndex=-1;
    node[newIndex].children=NULL;
    node[newIndex].flag=flag;
    node[newIndex].content[0]="\0";
    node[newIndex].is->open=0;
    
    //将新结点添加到孩子链表中
    Childenode* newnode=(Childnode*)malloc(sizeof(Childnode));
    newnode->childIndex=newIndex;
    newnode->next=
}

//主函数 
int main()
{
    initsystem();//创建根目录 
    
    char command[100];
    char str1[100];
    char str2[100];
    
    while(1)
    {
        cout<<">>";
        cin>>command;
         
        if(strcmp(command,"exit")==0)
            break;
        else if(strcmp(command,"create_file")==0){
            cin>>str1;
            create_file(str1);
        }
        else if(command,"create_dir")==0){
            cin>>str1;
            create_dir(str1);
        }
        else if(command,"rename_file")==0){
            cin>>str1;
            cin>>str2;
            rename_file(str1,str2);
        }
        else if(command,"rename_dir")==0){
            cin>>str1;
            cin>>str2;
            rename_dir(str1,str2);
        }
        else if(command,"ls")==0){
            //输出当前目录下的所有目录和文件
            ls(curdir); 
        }
        else if(command,"cd")==0){
            cin>>str1;
            cd(str1);
        }
        else if(command,"cd")==0){
            cin>>str1;
            cd(str1);
        }
        else if(command,"open")==0){
            cin>>str1;
            open(str1);
        }
        else if(command,"close_file")==0){
            cin>>str1;
            close();
        }
        else if(command,"read_file")==0){
            cin>>str1;
            read_file(str1);
        }
        else if(command,"write_file")==0){
            cin>>str1;
            write_file(str1);
        }
        else{
            //如果输入命令无效
            cout<<"ERROR:Invalid command"; 
        }
    }
}

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

热搜词