Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!wuarchive!psuvax1!psuvm!brl102 From: BRL102@psuvm.psu.edu (Ben Liblit) Newsgroups: comp.sys.apple2 Subject: Re: HyperC filing question Message-ID: <90312.134032BRL102@psuvm.psu.edu> Date: 8 Nov 90 18:40:32 GMT References: <1990Nov8.045226.7696@wpi.WPI.EDU> Organization: Penn State University Lines: 56 In article <1990Nov8.045226.7696@wpi.WPI.EDU>, greyelf@wpi.WPI.EDU (Michael J Pender) says: > >I'm trying to read and write binary files from Hyper C. >This was my closest attempt: [ I have omitted below all lines except those requiring modification. ] >#include Unless you renamed it, this should be . > FILE *fp = open("/ram/output.snd","wb"); ProDOS HyperC takes no second parameter -- if specified, it is ignored. (Yes, HyperC does absolutely no parameter checking.) > for(screen = 0x400; screen < 0x8; screen++) You want to scan as long as "screen < 0x800", not "screen < 0x8". Also, although HyperC couldn't care less, it is good programming practice to typecast the 0x400 and 0x800 to char pointers. More strict compilers will call you nasty names if you don't. > fprintf(*fp, "%x", *screen); Ok, here's the core of the problem. As I stated above, ProDOS HyperC takes only one parameter for open(). What this means is that it doesn't know the difference between binary and text files. It's all in how your program chooses to read and write the file. fprintf() is for text files ... for binary files, use read() and write(). Both take three parameters: first, the file designator (just as in fprintf()); second, a buffer usually de- clared as an array of or pointer to char; lastly, an integer specifying the length of the buffer in bytes. For those applications where only one byte (char) is being written at a e time, the most efficient technique would be to use putc(). It takes two parameters: first, the file designator as in fprintf(); second, the char- acter to be written. So instead of your fprintf() call, you really want: putc( *fp, *screen ); Actually, if all you're doing is a straight screen dump to disk, you can do the whole thing *really* efficiently using: write( *fp, (char *) 0x400, 0x400 ); and eliminate the loop completely. -- Hope this helps. -- Ben Liblit BRL102 @ psuvm.bitnet -- BRL102 @ psuvm.psu.edu "Fais que tes reves soient plus longs que la nuit."