[comp.lang.c] problems with struct w/in struct in TC

burleigh@cica.cica.indiana.edu (Frank Burleigh) (10/05/89)

here is yet another problem of something that seems as though it
should work, but which does not.  so i need to ask the obvious:
"am i doing this right?"

ms-dos defines a structure into which file directory information
is placed by the findfile/findnext functions.  the struct holds
stuff like file name, size, etc.  at the beginning of this struct
is a ms-reserved 21 byte char field for which i have no use.  as
i want to collect the directory data for the files in a dir in an
array of struct, i made two structs: one with the data i want, and
one with this big reserved field plus the data i want (see below).
after defining the structs, i declare an array of the struct with
the data i want, since, hey, why waste 21 bytes per file?

it doesn't work right.  it looks like the data isn't making it
from the 'sub' struct.  this can be seen in that the closing 
printf of all the file names fails miserably.  but this doesn't
surprise me, since TC2.0 is warning me in the findfile/findnext
calls that it sees "suspicious pointer conversion...", and my casts
don't make the warnings go away, i can only assume i have made some
tremendous, but not obvious to me, error.  

i would really appreciate some e-mail telling me what paths i can
follow to correct the problem.  meantime, i can just waste memory.

the relevant code follows.  thank you.

typedef struct  file_blka {  /*the data i want, later made an array*/
    char        ff_attrib;
    unsigned    ff_ftime;
    unsigned    ff_fdate;
    long        ff_fsize;
    char        ff_name[13];
} file_blka;

typedef struct  file_blk {   /*findfile/findnext need & of one of these*/
    char        ff_reserved[21];  /*the stuff i don't want*/
    struct file_blka    file_data;  /*the stuff i do want*/
} file_blk;

file_blk    file_temp;
file_blka   file_list[MAXFILES];

    int files = 0;
    findfirst( file_spec, (file_blk *) &file_temp, 0 );
    file_list[0] = file_temp.file_data;
    for( files = 1; (findnext( (file_blk *) &file_temp) ) != -1; files++ )
        file_list[i] = file_temp.file_data;
    for( i = 0; i <= files; i++ )
        printf( "%s\n", file_list[i].ff_name );

ps: please excuse these terrible names. :-)
pps: oddly, looking at the data structures in t-debugger suggests
that file_list is fine, but it sure doesn't want to work right...

-- 
Frank Burleigh  burleigh@cica.cica.indiana.edu
USENET: ...rutgers!iuvax!cica!burleigh BITNET: BURLEIGH@IUBACS.BITNET
Department of Sociology, Indiana University, Bloomington, Indiana 47405