-1

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?

Papipone
  • 1,083
  • 3
  • 20
  • 39
G. Lucas
  • 19
  • 1
  • 5
  • 2
    Q: Have you considered trying what the warnings tell you to do? ` is obsolete: consider using instead.` and ` is obsolete, consider using instead.`. SUGGESTIONS: 1) Try substituting "io.h" and "direct.h", 2) consider using `struct ffblk f;`. – paulsm4 Sep 09 '18 at 23:15
  • Yes. findfirst() is still said to be implicitly declared, and the storage size of the struct still isn't known, the only thing that changes is the name. – G. Lucas Sep 09 '18 at 23:33
  • 1
    You want [`_findfirst`](https://msdn.microsoft.com/en-us/library/zyzxfzac.aspx). – dbush Sep 09 '18 at 23:39
  • 3
    You want to see if you can use headers from this century :( – paulsm4 Sep 10 '18 at 00:06

1 Answers1

1

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.

paulsm4
  • 114,292
  • 17
  • 138
  • 190
  • Thanks! I was following an example code from a 2014 post that copied itself to other files on the folder, and it used both dos.h and dir.h, and findfirst() instead of _findfirst(). I didn't think that a header would be **really** obsolete for a language as old as C. – G. Lucas Sep 10 '18 at 02:28
  • Platforms (like "dos") come and go - C is Forever :) – paulsm4 Sep 10 '18 at 03:23