I want my program to take a directory, then print the contents of that directory and state whether or not each item is a directory or not. If I give it a directory containing fi
You're passing stat
the name of the file, but it needs a path to the file. If you check the return value for stat
, you'll see that it's only succeeding for .
and ..
, because they exist in any directory.
Canonical answer: Do not ever try to understand the behavior of a program that blows through error conditions. As soon as it's even the tiniest bit mysterious (at the latest), add code to check the return values of all functions.