2016-10-22 40 views
1

我正在學習編寫我自己的虛擬文件系統,但除了程序中的邏輯錯誤之外,還有一些不斷出現的內容,我檢查了程序中的所有聲明,但無法確定它出。錯誤C3861:'ls_file':標識符沒有找到

輔助函數

#include "header.h" 

UFDT UFDTArr[50]; 
SUPERBLOCK SUPERBLOCKobj; 
PINODE head=NULL; 

void man(char *name) 
{ 
    if(name==NULL) return; 

    if(_stricmp(name,"ls")==0) 
    { 
     printf("Description : Used to list all information of file\n"); 
     printf("Usage : ls\n"); 
    } 
    else 
    { 
     printf("ERROR : No manual entry available\n"); 
    } 
} 
    void DisplayHelp() 
{ 
    printf("ls : To List Out all files \n"); 
    printf("clear : To Clear consol\n"); 
} 

void CreateDILB() 
{ 
    PINODE newn=NULL; 
    PINODE temp=head; 
    int i=1; 

    while(i<=MAXINODE) 
    { 
     newn=(PINODE)malloc(sizeof(INODE)); 
     newn->LinkCount=newn->ReferenceCount=0; 
     newn->FileType=newn->FileSize=0; 
     newn->Buffer=NULL; 
     newn->next=NULL; 
     newn->InodeNumber=i; 

     if(temp==NULL) 
     { 
      head=newn; 
      temp=head; 
     } 
     else 
     { 
      temp->next=newn; 
      temp=temp->next; 
     } 
     i++; 
    } 

} 

void InitialiseSuperBlock() 
{ 
    int i=0; 
    while(i<50) 
    { 
     UFDTArr[i].ptrfiletable=NULL; 
     i++; 
    } 

    SUPERBLOCKobj.TotalInodes=MAXINODE; 
    SUPERBLOCKobj.FreeInode=MAXINODE; 
} 
void ls_file() 
{ 
    PINODE temp=head; 

    if(SUPERBLOCKobj.FreeInode== MAXINODE) 
    { 
     printf("Error : There are no files "); 
     return; 
    } 
    printf("\n File Name\tInode Number\tFile Size\tLink count\n"); 
    printf("------------------------------------------------------------"); 

    while(temp!=NULL) 
    { 
     if(temp->FileType!=0) 
     { 
      printf("%s\t\t%d\t\t%d\t\t%d\n"); 
     } 
     temp=temp->next; 
    } 
    printf("------------------------------------------------------------"); 
} 

主文件

#include "header.h" 

int main() 
{ 
    char *ptr=NULL; 
    int ret=0,fd=0,count=0; 
    char command[4][80],str[80],arr[1024]; 

    InitialiseSuperBlock(); 
    CreateDILB(); 

    while(1) 
    { 
     fflush(stdin); 
     strcpy_s(str,""); 

     printf("Sachin VFS :> "); 
     fgets(str,80,stdin); 

     count=sscanf(str,"%s%s%s %s",command[0],command[1],command[2],command[3]); 

     if(count==1) 
     { 
      if(_stricmp(command[0],"ls")==0) 
      { 
       ls_file(); 
      } 

      else if(_stricmp(command[0],"clear")==0) 
      { 
       system("cls"); 
       continue; 
      } 
     else 
     { 
      printf("\n ERROR : Command not found!!! \n"); 
      continue; 
     } 

    } 
    } 
    return 0; 
} 

頭文件

#define _CRT_SECURE_NO_WARNINGS 
#define MAXINODE 50 
#define READ 1 
#define WRITE 2 
#define MAXFILESIZE 1024 
#define REGULAR 1 
#define SPECIAL 2 
#define START 0 
#define CURRENT 1 
#define END 2 

#include<iostream> 
#include <stdlib.h> 
#include<string.h> 
#include<io.h> 

typedef struct superblock 
{ 
    int TotalInodes; 
    int FreeInode; 

}SUPERBLOCK,*PSUPERBLOCK; 

typedef struct inode 
{ 
    char FileName[50]; 
    int InodeNumber; 
    int FileSize; 
    int FileActualSize; 
    int FileType; 
    char *Buffer; 
    int LinkCount; 
    int ReferenceCount; 
    int permission; 
    struct inode *next; 

}INODE,*PINODE,**PPINODE; 

typedef struct filetable 
{ 
    int readoffset; 
    int writeoffset; 
    int count; 
    int mode; 
    PINODE ptrinode; 

}FILETABLE,*PFILETABLE; 

typedef struct ufdt 
{ 
    PFILETABLE ptrfiletable; 

}UFDT; 

所述一個解決這個問題,我得到被聲明在上述主要主文件到所有的功能使編譯器識別功能,但我仍然無法弄清楚它爲什麼不能識別s當我聲明他們在其他文件中的ame函數?

默認功能正在像system("cls");但我的功能不工作

任何人都可以幫助我理解這個錯誤和可能的解決方案的原因是什麼?我的代碼

PS-我已經粘貼小部分的實際代碼太長,如果有人想我將它張貼我將在註釋部分

回答

0

總之後 - 你應該在你的header.h聲明ls_file()

void ls_file(); 

這是一種常用的技術,可以將某些對象/函數導出到定義它們的文件之外。 「實施」和「客戶端」*.c文件都必須包含該標題。前者 - 爲了保證實際定義和公共可視聲明的一致性,後者是爲客戶代碼提供適當和明確的聲明。

...仍然無法弄清楚它爲什麼不能識別相同的功能當我在其他文件中聲明它們時 函數?

一般來說,編譯器應該在引用它們之前看到函數/全局變量的聲明或定義。這是因爲在編譯過程中,翻譯人員只能使用一個.c源文件,並且對其他源文件及其內容一無所知。

P.S This answer可能會讓你多一點點。

+0

謝謝你的幫助。 –

相關問題