delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1994/05/18/13:44:33

Date: Wed, 18 May 1994 13:04:19 -0400 (EDT)
From: SGW46959M021 AT DAFFY DOT MILLERSV DOT EDU
To: djgpp AT sun DOT soe DOT clarkson DOT edu
Subject: dirent probs.

Anybody know how to implement this code so that it doesn't crash (pointer 
segmentation violation) after the last entry in the directory is printed?
The eventual goal is to create a linked list of DATA items representing all
of the files on a drive (or possibly a tree, haven't decided). I'm new to using
both the dir.h & dirent.h functions, so any help would be appreciated.

						THANX!
						S. Walizer

#include <dirent.h>
#include <stdio.h>

main()
{
    typedef struct data{
        struct ffblk ff;
        struct dirent de;
    } DATA;

    DATA *dat;
    struct ffblk f;
    int done;

    done = findfirst("*.*", &f, FA_RDONLY|FA_HIDDEN|FA_SYSTEM|FA_LABEL|
        FA_DIREC|FA_ARCH);
    while (!done) {
        dat->ff = f; 
        printf("%d  %s    %c\n", done, dat->ff.ff_name, dat->ff.ff_attrib);
        done = findnext(&f);
    } 
}

- Raw text -


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