我有这个用于删除目录的代码。我有header1.h
, header1.c
, main.c
。
我收到一些错误,但对我来说更难理解的是以下错误:
(1)存储大小ffblk
不知道。
另外,我对如何定义 ffblk
的属性有疑问,分别是 ff_name 和 ff_attrib
这个例子来自互联网上的各种代码示例(甚至来自这里的其他代码示例),它们都执行相同的代码,只是在我的情况下它不起作用。
我错过了结构的定义吗?或者也许我在不应该是任何代码的地方添加了代码?
请你帮助我好吗?我通常不使用 C 语言编程,我使用 Dev-Cpp。
标题1.h:
#ifndef HEADER1_H_INCLUDED
#define HEADER1_H_INCLUDED
typedef struct ffblk ffblk;
#endif
标题.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\1\AppData\Local\Temp\cc89P309.o:Untitled3.c:(.text+0x8e): undefined reference to `findfirst'
C:\Users\1\AppData\Local\Temp\cc89P309.o:Untitled3.c:(.text+0x1d8): undefined reference to `findnext'
最佳答案
最后,问题始终出在函数 findfirst(a,b,c) 和 findnext(a,b,c) 上。我必须更改函数并使用带有 2 个参数而不是 3 个参数的版本。我将所有代码与包含、typedef 结构和下面的代码放在一个文件中。
关于C - 错误未定义且存储未知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46064842/