Mail Archives: djgpp/1994/05/18/13:44:33
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 -