# printf on Mac



## ultranet (Aug 29, 2005)

If one does
printf("something\n");
on a Mac,
does that print the right line-termination sequence for Mac OS? I am not sure, but i recall reading that the sequence was \n\r for earlier Mac releases. If so will the line above print \r\n into the stream?

Basically, i'm trying to determine if \n in printf is equivalent to cout << endl in C++.

Thanks.


----------



## Krevinek (Aug 29, 2005)

From what I can remember, printf("Stuff\n") will simply push just the '\n' (0x13). Although if you are truly curious as to what is going on... you can write a quick app that finds line-breaks from stdin and checks what type they are. I could be wrong about what I remember, but a line-break checker will reveal the truth. 

Then, just plug your existing app into this new one and run: <app> | break_finder

This is assuming both are CLI though.

Although no... "\n" is not the same as cout << endl;


----------



## ultranet (Aug 29, 2005)

The things is i don't have a Mac.

Here's an excerpt for Windows, which appears to be true for 2K, and XP:

"For example, on MS-DOS systems in text mode (which is the default), every time you output a newline character ('\n'), the file system actually outputs two characters, a carriage-return/linefeed pair (CRLF), which is the pair of ASCII characters 0x0D and 0x0A. Conversely, when you read such a file back into memory in text mode, each occurrence of this pair of bytes causes a '\n' to be sent to the ..."


This appears to make \n equivalent to \r\n in printf and on Windows. So i'm wodering if the same is true for Mac, although i guess Mac sequence is \n\r.


----------

