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 6118097
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T15:23:47+00:00 2026-05-23T15:23:47+00:00

I have a question regarding the following code: while((c = getc(pFile)) != EOF) {

  • 0

I have a question regarding the following code:

while((c = getc(pFile)) != EOF)
{
    if(c != '\n')
    {
         input[index] = (char)c;
         index++;
     } else
     {
         input[index] = '\0';
         index = 0;
     }
}

In Windows, this c = getc line reads ‘\n’ (code 10) twice. For example, I’m reading in the file with the following 2 lines:

Hello world
Test

c = getc reads in Hello world, but reads in 10 (\n) and 10 once more, resetting the input array to blank (because of the ‘\0’). In unix, the ‘\n’ only gets read once, so it all works.

Any idea?

Thanks in advance.

  • 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-05-23T15:23:48+00:00Added an answer on May 23, 2026 at 3:23 pm

    Is the file physically the same, i.e. bit-by-bit, on the two platforms? That’s asking for trouble, since the encoding for line ending differs.

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

Sidebar

Related Questions

I have a question regarding the following code snippet I came across in one
another noob question regarding F#. If I have the following code... let ExeC =
EDIT: Optimization results at end of this question! hi, i have a following code
I have a question regarding the following code: abstract class a { public static
I have a question regarding checkboxes. <form method=post> I speak the following languages: <input
I have a question regarding exception handling. Consider following Java code snippet. try{ //code
I have a question regarding memory allocation order. In the following code I allocate
I'm writing a small webapp in Grails and I have the following question regarding
Following on from my recent question regarding parsing XML files in Java I have
My question is regarding JavaScript Closures and the Eval() function. I have some code

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.