Message-Id: <3.0.6.32.19981117032200.007a2d70@tenforward.com> X-Sender: sw AT tenforward DOT com X-Mailer: QUALCOMM Windows Eudora Light Version 3.0.6 (32) Date: Tue, 17 Nov 1998 03:22:00 -0800 To: djgpp AT delorie DOT com From: Jeff Johnson Subject: Re: Array Headache! In-Reply-To: <72rbd0$h57@news2.jaring.my> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Reply-To: djgpp AT delorie DOT com 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...