delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/11/17/03:21:06

From: "deseeker" <deseeker AT yahoo DOT com>
Newsgroups: comp.os.msdos.djgpp
Subject: Array Headache!
Date: Tue, 17 Nov 1998 16:10:53 +0800
Organization: Unconfigured
Lines: 42
Message-ID: <72rbd0$h57@news2.jaring.my>
NNTP-Posting-Host: j26.sja.jaring.my
X-Newsreader: Microsoft Outlook Express 4.72.3110.1
X-MimeOLE: Produced By Microsoft MimeOLE V4.72.3110.3
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

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)

Thanx in advance.

deseeker




- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019