Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!purdue!bu-cs!dartvax!eleazar.dartmouth.edu!earleh From: earleh@eleazar.dartmouth.edu (Earle R. Horton) Newsgroups: comp.sys.mac.programmer Subject: Re: i.o. problem with MPW C Keywords: MPW, C Message-ID: <12798@dartvax.Dartmouth.EDU> Date: 29 Mar 89 00:23:44 GMT References: <222@uw-apl.UUCP> Sender: news@dartvax.Dartmouth.EDU Reply-To: earleh@eleazar.dartmouth.edu (Earle R. Horton) Distribution: na Organization: Thayer School of Engineering Lines: 48 In article <222@uw-apl.UUCP> keith@uw-apl.UUCP (Keith Kerr) writes: >I've just started using MPW C, and I'm having a problem with >very simple i/o. I've tried several variations of the following >program (which runs fine on UNIX), but without success. The >output file gets created, but upon completion it is either >empty, or unreadable. Any pointers as to what I'm doing >wrong would be helpful. When you "fopen()" a file for writing with MPW C, it has the default creator ' ' and default type ' ' unless you arrange for it to have something else. There wasn't anything wrong with this program, except that it created its output file to be a ' ' file instead of a 'TEXT' file, and your editor probably wouldn't open it. When using stdio to create files on the Mac with MPW C, you have to set the file type and creator, as below. ------------------------------------------------------------------ #include /* for buffered file output */ int main() /* prints out data to check it */ { FILE *out_file, *fopen(); char *filename = "check_file_out"; int how_much = 64, index, ok; Create(filename,0,'MPS ','TEXT'); /* So a text editor will open it. */ out_file = fopen(filename, "w"); if (out_file == NULL) { /*SysBeep(5);*/ return; } else for (index = 1; index <= how_much; ++index) fprintf(out_file, "This shoulda been %d\n", index); ok = fclose(out_file); if (ok == (-1)) { return; /*SysBeep(5);*/ /*SysBeep(5);*/ } return(0); } earleh:xyzzy:32768:7:Earle R. Horton,,,6434109:/hackers/earleh:/bin/rn