In a terminal I can call ls -d */. Now I want a c program to do that for me, like this:
#include
#include
Another less low-level approach, with system():
#include
int main(void)
{
system("/bin/ls -d */");
return 0;
}
Notice with system(), you don't need to fork(). However, I recall that we should avoid using system() when possible!
As Nomimal Animal said, this will fail when the number of subdirectories is too big! See his answer for more...