Article View: comp.sys.mac
Article #24721Re: SFGetFile in MPW C
From: Mike Blackwell
Date: Thu, 04 Feb 1988 18:12
Date: Thu, 04 Feb 1988 18:12
33 lines
1390 bytes
1390 bytes
I had the very same problem, and it took a lot of head scratching to figure
out what the hell was going on. The problem stems from the definition of
SFReply.fName. It's not a C string, and not really a P string, either - it's
a String(63) (see types.h). Here's a code fragment that does work:
DoLoad()
{
SFReply reply;
Point where;
char filename[100];
SFTypeList texttype;
extern pascal Boolean alignFiles();
FILE *fp;
texttype[0] = 'TEXT';
where.v = 100; where.h = 75;
SFGetFile(&where, "", alignFiles, 1, texttype, nil, &reply);
if (reply.good) {
SetVol(nil, reply.vRefnum);
strncpy(filename, reply.fName.text, reply.fName.length);
filename[reply.fName.length] = '\0';
if ((fp = fopen(filename, "r")) == nil) {
ErrorMessage("Could not open file:", filename);
} else {
... etc ...
}
}
}
Hope this helps...
Mike Blackwell ... mkb@rover.ri.cmu.edu
Technical Details
Message-ID:
<803@PT.CS.CMU.EDU>Path:
arc1-ca.pugleaf.net!utzoo!mnetor!uunet!lll-winken!lll-lcc!ames!ll-xn!mit-eddie!uw-beaver!cornell!rochester!PT.CS.CMU.EDU!ROVER.RI.CMU.EDU!mkbShow Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!mnetor!uunet!lll-winken!lll-lcc!ames!ll-xn!mit-eddie!uw-beaver!cornell!rochester!PT.CS.CMU.EDU!ROVER.RI.CMU.EDU!mkb From: mkb@ROVER.RI.CMU.EDU (Mike Blackwell) Newsgroups: comp.sys.mac Subject: Re: SFGetFile in MPW C Message-ID: <803@PT.CS.CMU.EDU> Date: 4 Feb 88 18:12:40 GMT Sender: netnews@PT.CS.CMU.EDU Reply-To: mkb@rover.ri.cmu.edu (Mike Blackwell) Organization: Carnegie-Mellon University, CS/RI Lines: 31