Newsgroups: comp.sys.mac.programmer Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!batcomputer!cornell!uw-beaver!steelhead.cs.washington.edu!chou From: chou@steelhead.cs.washington.edu (Pai Hsiang Chou) Subject: Re: Numbers from TEXT files under Think C ? Message-ID: <1991Apr22.142357.18338@beaver.cs.washington.edu> Sender: news@beaver.cs.washington.edu (USENET News System) Reply-To: chou@cs.washington.edu (Pai Hsiang Chou) Organization: Computer Science & Engineering, U. of Washington, Seattle References: <17150002@hpihoah.cup.hp.com> <4978@cernvax.cern.ch> Date: Mon, 22 Apr 91 14:23:57 GMT In article <4978@cernvax.cern.ch> marty@cernvax.cern.ch (hugues marty) writes: >In article <17150002@hpihoah.cup.hp.com> cring@hpihoah.cup.hp.com (Craig Ring) writes: >>I am writing a program in Think C 4.0 that needs to read numeric input from >>an ASCII text file. Under UNIX this is very easy to do with fscanf() and so >>on. Is there a simple way to do this with a Macintosh? >> >>I would like to be able to use SFGetFile() to allow the user to pick the >>file they would like to open, but the SFReply doesn't seem to be very useful >>to the ANSI C libraries for Think C. The Think C documentation says that >>scanf() requires a pointer to type FILE, which I am not sure how to get. How about fopen() with the filename? >One way is to call SFGetFile(), then geting the whole path name >for the selected file (for example "HD:folder 1:document") and passing >this string to the fopen() function which will return a FILE *. >The problem is how to get the file path... and I don't have >a sample code off-hand. If you have access to technical notes, >this is documented in TN 238 (Getting a full pathname). No, it's not a good idea (and not necessary) to use the full path name. There is a much simpler way. FILE *f; /* your SFGetFile() or SFPutFile() stuff */ if (sfreply.good) { char name[64]; SetVol(NULL,sfreply.vRefNum); /* set correct directory */ /* some procedure which copies a Pascal str to a C str */ PasToCStr(sfreply.fName, name); f = fopen(name, "r"); ... Pai Chou chou@june.cs.washington.edu