I've been trying to learn how can I use functions to interact with the paths on the system, but I guess I stucked at the very beginning.
I've searched web and stackoverflow especially and couldn't find a basic implementation like I am trying to do. There are some other questions, which is similar to mine, but I don't find them simple and beginner friendly like mine.
Here is the code, this code just prints the files in given path, and "." and ".."
#include <stdio.h>
#include <stdlib.h>
#include <dirent.h>
#include <sys/stat.h>
#include <string.h>
void listdir(DIR *c);
int main()
{
DIR* root_d;
root_d = opendir("/home/foo/Desktop/testx");
listdir(root_d);
}
void listdir(DIR *c){
DIR* current = c;
struct dirent *curr_ent;
if((curr_ent =readdir(current)) != NULL && curr_ent->d_type == DT_DIR){
listdir(current);
}
printf("%s\n", curr_ent->d_name);
return;
}
What am I doing wrong?