Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8172019
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T21:38:54+00:00 2026-06-06T21:38:54+00:00

I have a file with DOS line endings that I receive at run-time, so

  • 0

I have a file with DOS line endings that I receive at run-time, so I cannot convert the line endings to UNIX-style offline. Also, my app runs on both Windows and Linux. My app does an fgets() on the file and tries to read in line-by-line.

Would the number of bytes read per line on Linux also account for 2 trailing characters (\r \n) or would it contain only (\n) and the \r would be discarded by the underlying system?

EDIT:

Ok, so the line endings are preserved while reading a file on Linux, but I have run into another issue. On Windows, opening the file in “r” or “rb” is behaving differently. Does windows treat these two modes distinctly, unlike Linux?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T21:38:57+00:00Added an answer on June 6, 2026 at 9:38 pm

    fgets() keeps line endings.

    http://msdn.microsoft.com/en-us/library/c37dh6kf(v=vs.80).aspx

    fgets() itself doesn’t have any special options for converting line endings, but on Windows, you can choose to either open a file in “binary” mode, or in “text” mode. In text mode Windows converts the CR/LF sequence (C string: “\r\n”) into just a newline (C string: “\n”). It’s a feature so that you can write the same code for Windows and Linux and it will work (you don’t need “\r\n” on Windows and just “\n” on Linux).

    http://msdn.microsoft.com/en-US/library/yeby3zcb(v=vs.80)

    Note that the Windows call to fopen() takes the same arguments as the call to fopen() in Linux. The “binary” mode needs a non-standard character ('b') in the file mode, but the “text” mode is the default. So I suggest you just use the same code lines for Windows and Linux; the Windows version of fopen() is designed for that.

    The Linux version of the C library doesn’t have any tricky features. If the text file has CR/LF line endings, then that is what you get when you read it. Linux fopen() will accept a 'b' in the options, but ignores it!

    http://linux.die.net/man/3/fopen

    http://linux.die.net/man/3/fgets

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a bunch of files. Some are Unix line endings, many are DOS.
I have a Window .bat file with DOS commands that involve REM, MKDIR, ECHO,
We have a command line exe that takes input from a text file and
Using vim's :source command on a vimscript file with dos line endings is giving
As you all know, the line endings in DOS/Windows file differ than those of
In a DOS batch file we can only have 1 line if statement body?
I have a java file TestOutput.java that we need to run only on Sundays.
I have a csv file into which has crept some ^M dos line ends,
In Autosys, I have a job that executes a fairly simple DOS batch file
I have a text file exported from a Foxpro (Dos-based) program, but this text

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.