Jump to content
View in the app

A better way to browse. Learn more.

Tuts 4 You

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

fopen & fwrite Line Breaks Macintosh issue

Featured Replies

Posted

Hi guys,

I'am using those C functions above to read / write data to file and have that problem with the Macintosh CR (see notepate status bar).In normal case I write text fields like this...

db "Some Info", 13,10
db "Here too", 13,10
db "Look not!",0

....just 3 test lins with one line break between.Now if I do use the fwrite function with it then it does write the LBs in double LBs like this...

db "Some Info", 13,10,13,10
db "Here too", 13,10,13,10
db "Look not!",0

....and not in Unix style.How can I tell the function using Unix style instead of Macintosh?

greetz

First, you're mixing up line endings:

  • DOS/Windows line endings are CR+LF (in decimal 13, 10)
  • Linux/Unix line endings is LF (10)
  • Macintosh line ending is CR (13)

So, which ones do you have and which ones do you want?

 

Second - fread()/fwrite() function works differently, depending on what flags you pass to fopen(). If you open file as text (default), fread/fwrite will change line endings. If you don't want your line endings to change, just open the file with "b" flag.
Something like this:

pFile = fopen("myfile.txt","wb");
fwrite(pFile, something....)

As always, MSDN explains it in more details:
https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/fopen-wfopen?view=msvc-160#generic-text-routine-mappings
https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/fwrite?view=msvc-160#remarks
https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/fread?view=msvc-160#remarks

 

Create an account or sign in to comment

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.