Commit 97d5a621 authored by Zara Saldanha's avatar Zara Saldanha

Update traverse.c

parent 564f20b4
......@@ -50,6 +50,7 @@ void process(char *root)
unsigned int fd;
int num_dir = 0;
struct stat file_info;
time_t least_mod = INT_MAX;
struct dirent *dp;
DIR *dirp;
......@@ -57,7 +58,8 @@ void process(char *root)
initq(&nameq);
enqueue(root,&nameq);
time_t latest = 0;
char dName[MAXLENGTH];
char newest[MAXLENGTH];
char oldest[MAXLENGTH];
struct stat dStat;
while (true != queue_empty(nameq)) {
peek_front(dname,nameq);
......@@ -84,9 +86,13 @@ void process(char *root)
enqueue(cname,&nameq);
}
if (dStat.st_mtime > latest) {
strcpy(dName, dp->d_name);
strcpy(newest, dp->d_name);
latest = file_info.st_mtime;
}
if (dStat.st_mtime < least_mod) {
strcpy(oldest, dp->d_name);
least_mod = file_info.st_mtime;
}
}
closedir (dirp);
} else {
......@@ -118,8 +124,8 @@ void process(char *root)
printf(" the max file size is %d bytes\n",(int)max);
printf(" the min file size is %d bytes\n",(int)min);
printf(" the average file size is %f bytes\n",avg);
printf(" the file size that was most recently modified: %s\n",dName);
printf(" the file that was least recently modified is %f\n",avg);
printf(" the file size that was most recently modified: %s\n",newest);
printf(" the file that was least recently modified is %s\n",oldest);
}
// initialize queue data structure
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment