delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/1999/07/20/11:50:36

Mailing-List: contact cygwin-help AT sourceware DOT cygnus DOT com; run by ezmlm
Sender: cygwin-owner AT sourceware DOT cygnus DOT com
Delivered-To: mailing list cygwin AT sourceware DOT cygnus DOT com
References: <213ED6CF802ED111A0AB00805F0DD471F9ED2A AT WN01EX>
Cc: cygwin AT sourceware DOT cygnus DOT com
In-Reply-To: <213ED6CF802ED111A0AB00805F0DD471F9ED2A@WN01EX> (Marco.Craveiro@solvay.com)
To: Marco DOT Craveiro AT solvay DOT com
Subject: Re: newbie: _findfirst bug or is it me?
From: Nick Sieger <Nick AT mpen DOT com>
Date: Tue, 20 Jul 1999 11:46:54 -0400
Message-Id: <99Jul20.114846edt.16129@guard.mpen.com>
Lines: 51

>>>>> "Marco" == Craveiro, Marco <Marco DOT Craveiro AT solvay DOT com> writes:

Marco> #include <dir.h>
Marco> #include <iostream.h>

Marco> void main()
Marco> {
Marco>    int iHandle;
Marco>    int iResult;

Marco>    struct _finddata_t * find;
	struct _finddata_t find;
 
Marco>    iResult = _chdir ("c:\\");  
Marco>    iHandle = _findfirst ("*.txt", find); 
	iHandle = _findfirst ("*.txt", & find);

Marco>    if ((iHandle == -1)) 
Marco>       cout << "no files found.";
Marco>    else
Marco>    {      
Marco>       cout << find->name << "\n";
	cout << find.name << "\n";
Marco>       while (!(iResult == -1))
Marco>       {
Marco>          iResult = _findnext (iHandle, find);
	iResult = _findnext (iHandle, &find);
Marco>          cout << find->name << "\n";
	cout << find.name << "\n";
Marco>       }
Marco>       _findclose (iHandle);
Marco>    }
Marco> }

Marco> it produces an ilegal operation if i run it. (crashes in the _findfirst). do
Marco> i need to do something different to use <dir.h>?? can anybody tell me what
Marco> am i doing wrong?

_findfirst() expects that the pointer argument actually points to a
valid structure.  You just passed a pointer that points nowhere.
Maybe you thought that it would allocate memory for you, when in fact
it does not.  That is usually the convention with those type of
functions where a pointer to structure argument is taken.

Hope it helps.
nick

-- 
-- Nick Sieger -- MPen Inc. -- mailto: nick AT mpen DOT com -- http://www.mpen.com
	-- Tel: 212-807-9608 x6464 -- Fax: 212-675-6121 --


--
Want to unsubscribe from this list?
Send a message to cygwin-unsubscribe AT sourceware DOT cygnus DOT com

- Raw text -


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