Consider yourself to look at man pages. In short stat() returns:
On success, zero is returned. On error, -1 is returned, and errno is
set appropriately.
And the errno's list is:
- EACCES
- EBADF
- EFAULT
- ELOOP
- ENAMETOOLONG
- ENOENT
- ENOMEM
- ENOTDIR
- EOVERFLOW
After calling stat, check it's return value with and if it equals -1, check errno (with switch).
Example:
if(stat(files[i-1]->d_name,fileStat)) {
switch(errno) {
case EACCES:
// Add code or at least
perror("STAT ERROR:");
break;
case EBADF:
// ...
break;
case EFAULT:
// ...
break;
// ...
// Do this to all possible errno's for the stat
// ...
case EOVERFLOW:
// ...
break;
}
}
If you have troubles with storing path, try to declare array as this (if you using linux):
#include <linux/limits.h>
//...
char current_path[PATH_MAX];
If you using Windows:
#include <windows.h>
//...
char current_path[MAX_PATH];
P.S. Thanks for Jonathan Leffler for pointing out my switch typo :)