Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!uwm.edu!wuarchive!udel!rochester!pt.cs.cmu.edu!b.gp.cs.cmu.edu!Ralf.Brown@B.GP.CS.CMU.EDU From: Ralf.Brown@B.GP.CS.CMU.EDU Newsgroups: comp.sys.ibm.pc Subject: Re: TC2: problem filling array of struct w/ findnext Message-ID: <252b38ea@ralf> Date: 5 Oct 89 11:20:10 GMT Sender: ralf@b.gp.cs.cmu.edu Organization: Carnegie Mellon University School of Computer Science Lines: 39 In-Reply-To: <154@cica.cica.indiana.edu> In article <154@cica.cica.indiana.edu>, burleigh@cica.cica.indiana.edu (Frank Burleigh) wrote: >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 >properly referencing the addresses of the file_list array of >struct. the intent is simply to have findfirst/findnext put a >list of file into the file_list[i]. instead, the first file goes >in correctly, but then we drop out of the for loop with fnd = -1, >meaning either the filespec is bad or we've exhausted the dir. >this should not be happening. Yes, it should. DOS initializes the reserved fields of the ffblk on calling findfirst(), so that it knows where to continue searching when you do a findnext(). To make a list, you need something like the following: struct ffblk ffb ; char file_list[20][14] ; int fnd ; int count = 0 ; fnd = findfirst( "*.*", &ffb, 0 ) ; while (fnd != -1 && count < 20) { strcpy(file_list[count++],ffb.ff_name) ; fnd = findnext(&ffb) ; } -- UUCP: {ucbvax,harvard}!cs.cmu.edu!ralf -=-=-=-=- Voice: (412) 268-3053 (school) ARPA: ralf@cs.cmu.edu BIT: ralf%cs.cmu.edu@CMUCCVMA FIDO: Ralf Brown 1:129/46 FAX: available on request Disclaimer? I claimed something? "Common sense is the collection of prejudices acquired by age eighteen" -- Albert Einstein