Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

using readdir to count files in a directory 1

Status
Not open for further replies.

ravenspawn

Technical User
May 3, 2001
13
0
0
US

struct S_Dir* dirp;
struct dirent* direntp;

dirp = opendir( "C:/WINDOWS/Desktop/OATS_MONITOR/OATS/usr/home/clf" );
if( dirp != NULL ) {
for(;;) {
direntp = readdir( dirp);
if( direntp == NULL ) break;

printf( "%s\n", direntp->d_name );
}

closedir(dirp );


}
I get errors saying:
ATS.obj : error LNK2001: unresolved external symbol "void __cdecl closedir(struct S_Dir *)" (?closedir@@YAXPAUS_Dir@@@Z)
OATS.obj : error LNK2001: unresolved external symbol "struct dirent * __cdecl readdir(struct S_Dir *)" (?readdir@@YAPAUdirent@@PAUS_Dir@@@Z)
OATS.obj : error LNK2001: unresolved external symbol "struct S_Dir * __cdecl opendir(char *)" (?opendir@@YAPAUS_Dir@@PAD@Z)
Debug/OATS.exe : fatal error LNK1120: 3 unresolved externals
Error executing link.exe.

OATS.exe - 4 error(s), 0 warning(s)
 
The Errors coming because of S_Dir. Use Struct DIR.
Try the following program.


#include <stdio.h>
#include <sys/types.h>
#include <dirent.h>
int main()
{
int count;
struct DIR *d;
if( (d = opendir(&quot;.&quot;)) != NULL)
{
for(count = 0; readdir(d) != NULL; count++);
closedir(d);
}
printf(&quot;\n %d&quot;, count);
return 0;
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top