[comp.sys.mac.programmer] r vs n in Think C 4.0

munroe@batroc.dmc.com (Dick Munroe) (02/16/90)

Mike Engber engber@gumball.ils.nwu.edu writes:

I was experimenting in Think C (4.0) and it seems that the stdio routines
don`t properly distinguish \n and \r.

I was under the impression that on the Mac, lines were separated by
returns, \r. But whenever I read I get newlines, \n, instead. Similarly,
when I print out \n's, \r`s seem to really get output.

Now this may be a feature to help portability across UNIX systems that
use newlines as line separators, but I was unable to find this documented
in the manuals.

What gives?

-ME

Mike,

Congratulations, you ran into a bomb that SHOULD have been in stdio
since day 1.  The Mac file system can operate in one of two modes
one converts \r to \n, the other doesn't.  I'm not quite sure why
Think came up with this change right now, but they sure did.  In any event,
I think if you open files in text mode \r gets converted.  When you open
them in binary mode, they don't.

I solved the problem by generating all files that are read exclusively by think
in binary mode.  When I export the files, i.e., write files that might be read
by Word or an editting DA I write the file in text mode.

Yechh.

Dick Munroe

--
Dick Munroe				uunet!batroc!munroe (UUCP)
Doyle Munroe Consultants		munroe@batroc.dmc.com (Domain)
267 Cox Street				(508) 568-1618
Hudson, Ma. 01749			(508) 562-1133 (FAX)

minow@mountn.dec.com (Martin Minow) (02/19/90)

>Mike Engber engber@gumball.ils.nwu.edu writes:
>
>I was experimenting in Think C (4.0) and it seems that the stdio routines
>don`t properly distinguish \n and \r.
>
>I was under the impression that on the Mac, lines were separated by
>returns, \r. But whenever I read I get newlines, \n, instead. Similarly,
>when I print out \n's, \r`s seem to really get output.
>

This is required by the Ansi Standard.  Stdio must translate between
'\n' and whatever the operating system requires (<CR> on the Mac,
<LF> on generic Unix, <CR><LF> on other systems, operating-system
magic on line-oriented systems).

The idea between stdio is that it isolates your program from having
to deal with the underlying mechanisms.  If you want to process the
actual values in the file, you must either use a non-stdio routine
(the Mac's  FS... and PB... families) or -- in some cases -- open
the file using "binary" mode (this works for files, but might not
work for the display or keyboard as you might wish).

Martin Minow
minow@thundr.enet.dec.com