Hi, I'm trying to do a small C program that changes the current directory.
Code:
#include <unistd.h>
char *directory = ".";
void changedir()
{
directory = "/tmp";
if (chdir(directory) != 0)
perror("chdir() to %s failed\n", directory);
printf("%s\n", directory);
}
int main()
{
changedir();
}
The problem is that, I don't know what to do with the variable directory.
Ie, if I want to first, change directory and them do an ls of the new directory ( I know that I don't have the ls part here), I must do an ls with the directory value has an argument?
Ex:
Code:
...
execl("ls", directory, (char *) 0);
...
I must keep the value of the directory?
Thanks,
Pedro