list files in a directory

Hello! I need to list the contents of a directory into an array..
I tried using readdir but it kept returning errors :S

1) can you give me some instruction on listing contents in a directory?
2) Is there a way to echo system commands into a variable/array?

thanks

EDIT
1
2
3
4
5
6
7
8
9
10
11
12
13
14
 

#include <dirent.h>

...

int main () {
  readdir("/home");

...

  return 0;
}
Last edited on
RTFM.
readdir expects a DIR * and return a dirent * that is an entry in the directory.
opendir returns DIR * with a path as parameter.
Don't forget closedir.

2) system is evil http://www.cplusplus.com/forum/articles/11153/
code example please? :D
Im rusty on c/c++ so.. yeha :S
and i did read the man.. it isnt very clear though
http://www.cplusplus.com/forum/unices/3480/#msg14680

You should try searching the forum. This has been answered many times.
Last edited on
hmmk sorry for my noobdulance :P I got it working :D
Topic archived. No new replies allowed.