我正在尝试制作一个测试程序,仅搜索其根文件夹中的任何文件:
#include <stdio.h>
#include <dir.h>
#include <dos.h>
struct ffblk ffblk;
int main(){
int result = findfirst("*.*", &ffblk,FA_ARCH);
return 0;
}
但是当代码编译时,ffblk
struct
声明返回错误:
storage size of ffblk isn't known
并且 findfirst()
函数返回:
warning: implicit declaration of function 'findfirst'[-Wimplicit-function-declaration]
as seen in this image ,即使 findfirst
和 ffblk
都是已包含在 dir.h
中的成员。我正在使用 Visual Studio
并使用 GCC
进行编译。有人知道代码或头文件有什么问题吗?
最佳答案
如果你能完全避免的话,你真的、真的不应该使用像“dos.h”这样过时的 header 中的过时的 API。诚实!
尽管如此,如果您坚持...
正如 dbush 所指出的,实际(已过时!)API 是
_findfirst
(而不是findfirst
)。记录在案here
您将看到此 API 的参数(同样 - 已过时)是
struct _finddata_t *fileinfo
(而不是struct ffblk
) >).
更改您的代码,一切都应该编译并运行。
更好的是,更改 header (更改为“io.h”和“dir.h”) - 原始代码可能应该编译并运行。
关于尽管函数和结构是包含的头文件的成员,但 C 错误 : implicit declaration of function and storage size isn't known,,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52249337/