Mail Archives: djgpp/1998/11/17/06:25:04
At 04:10 PM 11/17/98 +0800, you wrote:
>Hi,
>
>I am trying to write a small program to detect the number of files in a
>directory and the filenames
>
>/* Quick and dirty test routine */
>#define MAX_FILE 1000
>
>void main()
>{
> int i;
> char fn[MAX_FILE][256];
> DIR *path;
> struct dirent *dir;
> path = opendir("c:/test");
> while((dir = readdir(path))) {
> fn[++i] = dir->d_name;
> }
>}
>
>Ok, the above works fine but when MAX_FILE is *larger*, it return err 255.
>Then I came to the idea of using pointer b'cos it can hold large data
> char *fn[256]
> ...
> ++*fn = dir->d_name;
> ...
>Somebody would propably laughing already! After a idiotic trial and error, I
>found out that the dir->d_name has the same address each time. So I endup
>getting a list of the same (last)filename in fn b'cos each *fn is the SAME.
>After that, I though of writing the output to a file could solve the
>prob(Haven't try yet) but I don't want to.
>
>Can anybody help me how to create a large array to hold each filename (IF
>file numbers way way larger)
>
I'm not sure I know exactly what your talking about, so tell me if this
helps any...
What if you used vectors?
Say, when it found a file, it dumped it to vector file[i] then added 1 to
i, went through
again, dumped the next file to vector file[i] added 1 to i.....etc.
Before You say anything, yes i know vectotrs can only hold 100, (from
0-99), so, in this
great loop, you say, "when i == 99, start using file2[j], and continue the
same loop but
using file2[j]...Tell Me If I'm Just Ranting The Stupidly Obvious, Or
Anything Like That...
- Raw text -