cstructcompiler-errorsfindfirst

C errors: implicit declaration of function and storage size isn't known, despite the function and struct being members of an included header file


I'm trying to make a test program that simply searches for any file in its root folder:

#include <stdio.h>
#include <dir.h>
#include <dos.h>

struct ffblk ffblk;

int main(){
    int result = findfirst("*.*", &ffblk,FA_ARCH);
    return 0;
}

But when the code compiles, the ffblk struct declaration returns the error:

storage size of ffblk isn't known

and the findfirst() function returns:

warning: implicit declaration of function 'findfirst'[-Wimplicit-function-declaration]

as seen in this image, even though both findfirst and ffblk are members of dir.h, which is already included. I'm using Visual Studio and compiling with GCC. Does someone know what is wrong with the code, or the header files?


Solution

  • You really, really shouldn't be using obsolete APIs from obsolete headers like "dos.h" if you can at all avoid it. Honest!

    Nevertheless, if you insist...

    1. As dbush pointed out, the actual (obsolete!) API is _findfirst (not findfirst).

    2. It is documented here

    3. You'll see that the argument for this (again - OBSOLETE) API is struct _finddata_t *fileinfo (not struct ffblk).

    Change your code, and everything should compile and run.

    Better, change your headers (to "io.h" and "dir.h") - and the original code should probably compile and run.