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

  • Home
  • SEARCH
  • 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 8744533
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T11:51:19+00:00 2026-06-13T11:51:19+00:00

I guess the title speaks for itself. I am coding a C program on

  • 0

I guess the title speaks for itself.

I am coding a C program on Windows 7, using g++ and Notepad++, which compares content of files.

Content of the file:

simple
file with lines

File has line endings in windows style CRLF.

When I count the length of file using this code:

fseek(file, 0, SEEK_END);
size = ftell(file);
fseek(file, 0, SEEK_SET);

I get 23.

When I change line endings to Unix format LF (using Notepad++) I get 22 length.

This creates kind of a problem, when comparing two files. That’s why I ask, if there is a way to determine if given file has LF or CR or CRLF.

I know that I can distinguish between CR and LF, LF has ascii code 10 and CR has ascii code 13. Or LF is ‘\n’ and CR is ‘\r’.

But when reading file char after char I always get LF (ascii 10), even if there is CRLF.

I hope I made it clear. Thanks.

  • 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-13T11:51:20+00:00Added an answer on June 13, 2026 at 11:51 am

    That is the difference between reading files in text and binary mode.

    In text mode (fopen with the relevant parameters fopen( file, "r") then getc etc) all line ends are read as one character. If you read in binary mode e.g. fopen(file, "rb") then you will get the actual bytes and you will see CRLF and CR as different. fseek will use the actual number of bytes and so sees the difference in line endings.

    And the only way to tell is to read the files in the two different ways and see if there are CRLF pairs or the size differs, or in practice just see if there is a LF as I fdon’t think any current major OS uses that as a line enfing.

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

Sidebar

Related Questions

In my markup I am using HTML title attributes which I set by the
like the title. I guess it is the matter of file's name. But I
I guess the question title sums it up. Is there a time when it
As you can guess from the title, the outlining with regions finally made me
I guess my general question which I googled to no luck: Is there a
I guess the title almost says it all. My original url looks like: http://www.something.com/buy/index.php?p=025823
I guess the question is in the title: I want to apply a style
I guess I am not saying it right in the title. What I intend
I guess that title is self-explanatory. Is there any such effort been made? Some
I guess everything is in the title... I know that Dictionary<TKey,TValue> does keep the

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.