How to list first level directories only in C?
问题 In a terminal I can call ls -d */ . Now I want a c program to do that for me, like this: #include <sys/types.h> #include <sys/wait.h> #include <stdio.h> #include <unistd.h> int main( void ) { int status; char *args[] = { "/bin/ls", "-l", NULL }; if ( fork() == 0 ) execv( args[0], args ); else wait( &status ); return 0; } This will ls -l everything. However, when I am trying: char *args[] = { "/bin/ls", "-d", "*/", NULL }; I will get a runtime error: ls: */: No such file or directory 回答1: