Path: utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!apple!sun-barr!newstop!texsun!letni!merch!spudge!thorp
From: thorp@spudge.UUCP (Don Thorp)
Newsgroups: comp.sys.ibm.pc
Subject: Re: TC2: problem filling array of struct w/ findnext
Keywords: turbo c array structure findnext
Message-ID: <4146@spudge.UUCP>
Date: 6 Oct 89 14:54:23 GMT
References: <154@cica.cica.indiana.edu>
Reply-To: thorp@spudge.UUCP (Don Thorp)
Distribution: na
Organization: Friends of Guru Bob
Lines: 55
In article <154@cica.cica.indiana.edu> burleigh@cica.cica.indiana.edu (Frank Burleigh) writes:
>once again i need to draw on net.experience.
>
>this code:
>
>#include
>#include
>
>struct ffblk file_list[20];
>int fnd = 0;
>
>fnd = findfirst( "*.*", file_list+0, 0 );
>for( i = 1; fnd != -1; i++ )
> fnd = findnext( file_list+i );
>
>does not work right, and i have no doubt it is because i am not
>thank you muchly.
>
>btw, this is tc2.0 and pc dos 4.01.
>
>--
>Frank Burleigh burleigh@cica.cica.indiana.edu
>USENET: ...rutgers!iuvax!cica!burleigh BITNET: BURLEIGH@IUBACS.BITNET
>Department of Sociology, Indiana University, Bloomington, Indiana 47405
I haven't tested the following code, but I'm pretty sure that it will do
the job.
#include
#include
struct ffblk file_list[20];
struct ffblk tmpf;
int i;
if(findfirst("*.*",&tmpf,0) == 0) {
file_list[0] = tmpf; /* Save the directory structure */
for(i=1;i < 20; i++) {
if(findnext(&tmpf) == -1)
break;
file_list[i] = tmpf; /* structure copy non-K&R */
}
}
The reason the code didn't work, was that findnext expects the same structure
to be passed to it until no more files are found. findfirst sets up the
struct ffblk with information that findnext needs to find the next file.
You were passing an "uninitialized" struct ffblk* to findnext so it failed.
ps: you would have also run passed the end of the array if it had worked.
Good Luck
Don Thorp
USENET : ...!texbell!letni!rwsys!spudge!thorp