#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <string.h>
#include <pwd.h>
#include <grp.h>
#include <time.h>
#include <sys/types.h>
#include <dirent.h>
#include <unistd.h>
int main(int argc, char* argv[])
{
struct stat buf;
struct passwd* user;
struct group* grp;
struct tm* tm_ptr;
struct dirent* dirbuf;
int file_desc;
int stat_info;
char* directory;
char* filename;
char file_type;
char timebuf[14];
int stat_ret;
time_t modtime;
DIR* dp;
if (argc !=2)
{
printf("Invalid number of arguments\n");
return(1);
}
//open and read directory entries */
if ((dp = opendir(argv[1])) == NULL);
{
printf("error opening directory %s\n",argv[1]);
perror("opendir");
return(1);
}
/* ...and a bunch of other stuff that works fine */
whether or not the directory exists in the current directory, I get an "error opening directory". It's exactly the same as the code in the book unless I am missing something incredibly stupid. I added the perror to see what the actual error is, and It prints out 'SUCCESS'. The program never gets past this point at all, so I didn't bother to post 200 more lines of stuff. I've looked at online examples and they looked the same. I'm stuck until I can figure out how to open the dir, and loop through each directory entry. Thanks