C - 错误未定义且存储未知

C - ERROR not defined and storage unknown

我有删除目录的代码。我有 header1.hheader1.cmain.c。 我遇到了一些错误,但我更难理解的是错误: (1) ffblk 的存储大小未知。 另外,我有疑问如何定义ffblk的属性,即ff_name和ff_attrib 这个例子来自互联网上的各种代码示例(甚至来自这里的其他代码示例),它们都执行相同的代码,只是在我的例子中它不起作用。 我错过了结构的定义吗?或者也许我在不应该是任何代码的地方添加了代码? 请你帮助我好吗?我通常不使用 C 编程,我正在使用 Dev-Cpp.

header1.h:

#ifndef HEADER1_H_INCLUDED
#define HEADER1_H_INCLUDED

typedef struct ffblk ffblk;

#endif

header.c:

#include <stdio.h>
#include <stdlib.h>
#include "header1.h"
struct ffblk
{
    char ff_attrib[20];  //this line i added just so dont show error of unknown
    char ff_name[20];  //this line i added just so dont show error of unknown
};

main.c:

#ifndef FA_RDONLY
  #define FA_RDONLY _A_RDONLY
 #endif

#ifndef FA_HIDDEN
  #define FA_HIDDEN _A_HIDDEN
 #endif

 #ifndef FA_SYSTEM
  #define FA_SYSTEM _A_SYSTEM
 #endif

 #ifndef FA_DIREC
  #define FA_DIREC _A_SUBDIR
 #endif

 #ifndef FA_ARCH
  #define FA_ARCH _A_ARCH
 #endif


# include <stdio.h>
# include <dos.h>
# include <dir.h>
# include <io.h>
# include <conio.h>
#include "header1.h"

    typedef struct ffblk ffblk;

int BorrarArchivo(char *nombarch)
{
   printf("Borrando Archivo %s \n",nombarch);

   remove(nombarch);

   return 0;
}

int EliminarAtributo(char *nombarch,int atributo)
{
   printf("Elimina Atributo %s   %d\n",nombarch,atributo);

   chmod(nombarch,atributo);

   return 0;
}

int BorrarArbol(void)
{  
   struct ffblk ffblk;
   int done,err;

   err=0;
   done=findfirst("*.*",&ffblk,FA_RDONLY|FA_HIDDEN|FA_DIREC|FA_ARCH|FA_SYSTEM);

   while (!done)
   {
     if (FA_HIDDEN & ffblk.ff_attrib)
         EliminarAtributo(ffblk.ff_name,FA_HIDDEN);

     if (FA_SYSTEM & ffblk.ff_attrib)
         EliminarAtributo(ffblk.ff_name,FA_SYSTEM);

     if (FA_RDONLY & ffblk.ff_attrib)
         EliminarAtributo(ffblk.ff_name,FA_RDONLY);

     if (FA_ARCH & ffblk.ff_attrib)
         err=BorrarArchivo(ffblk.ff_name);
     else if (FA_DIREC & ffblk.ff_attrib)
     {
        if (ffblk.ff_name[0]!='.')
        { 
            chdir(ffblk.ff_name);

            err=BorrarArbol();

            chdir("..");

            if (!err)  
                printf("Removiendo %s\n",ffblk.ff_name);

            rmdir(ffblk.ff_name);
        }
     }
     else
        err=BorrarArchivo(ffblk.ff_name);

     if (err)
     {  
        printf("Error en el borrado ... !"); return err;
     }

     done=findnext(&ffblk);
    }

   return 0;
}

int main (void)
{ int err=0;
  char c;
    printf("Esta seguro  [ Si -> S , No ->otra tecla ] =>");
    c=getchar();
    if (!(c=='S' || c=='s')) return 0;
    err=BorrarArbol();
    if (err) printf("Error en el borrado ... !");
    return err;
}

编辑: 我找到了 struct 的定义并将其粘贴到 header.h

typedef struct ffblk {
      char lfn_magic[6];        /* LFN: the magic "LFN32" signature */
      short lfn_handle;     /* LFN: the handle used by findfirst/findnext */
      unsigned short lfn_ctime; /* LFN: file creation time */
      unsigned short lfn_cdate; /* LFN: file creation date */
      unsigned short lfn_atime; /* LFN: file last access time (usually 0) */
      unsigned short lfn_adate; /* LFN: file last access date */
      char ff_reserved[5];      /* used to hold the state of the search */
      unsigned char ff_attrib;  /* actual attributes of the file found */
      unsigned short ff_ftime;  /* hours:5, minutes:6, (seconds/2):5 */
      unsigned short ff_fdate;  /* (year-1980):7, month:4, day:5 */
      unsigned long ff_fsize;   /* size of file */
      char ff_name[260];        /* name of file as ASCIIZ string */
    }ffblk;

现在显示错误:

C:\Users\AppData\Local\Temp\cc89P309.o:Untitled3.c:(.text+0x8e): undefined reference to `findfirst'
C:\Users\AppData\Local\Temp\cc89P309.o:Untitled3.c:(.text+0x1d8): undefined reference to `findnext'

最后,问题始终是函数 findfirst(a,b,c) 和 findnext(a,b,c)。我不得不更改函数并使用带有 2 个参数而不是 3 个参数的版本。我将所有代码放在一个文件中,其中包含 include、typedef 结构和下面的代码。