I'm new to C and trying to understand why this code just return current directory file listing rather than the directory i pass to.
I used c11 standard gcc compiler
and just using ./a.out filedirectory .....
int main(int argc, char *argv[])
{
char*args[3];
if(argc > 1)
{
args[0] = "/bin/ls";
args[1] = "-l";
if(argv[2])
{
args[2] = argv[2];
args[3] = NULL;
}
else
{
args[2] = NULL;
}
execvp(args[0],args);
return 0;
}
}