dirp->d_name
is the name of the file in the directory: for example, "udpclient.c"
. The full name of the file is thus "/home/eipe/c/udpclient.c"
– but your current working directory is /home/eipe
, so stat()
is trying to access "/home/eipe/udpclient.c"
, which doesn’t exist.
You can either change your working directory to argv[1]
using chdir()
, or you can prepend argv[1]
to each filename before you call stat()
.