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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T09:15:58+00:00 2026-06-05T09:15:58+00:00

Im having an issue reading in lines from a file. Basically my code is

  • 0

Im having an issue reading in lines from a file. Basically my code is reading in one extra line than it should with all variables being ‘0’i.e.

If my file is:

0, 0, 3, 64, 0, 0, 0, 0
2, 0, 6, 64, 0, 0, 0, 0
4, 0, 4, 64, 0, 0, 0, 0
6, 0, 5, 64, 0, 0, 0, 0
8, 0, 2, 64, 0, 0, 0, 0

it will read in:

Object 1:  0, 0, 3, 64, 0, 0, 0, 0
Object 2:  2, 0, 6, 64, 0, 0, 0, 0
Object 3:  4, 0, 4, 64, 0, 0, 0, 0
Object 4:  6, 0, 5, 64, 0, 0, 0, 0
Object 5:  8, 0, 2, 64, 0, 0, 0, 0
Object 6:  0, 0, 0,  0, 0, 0, 0, 0

Here is my read algorithm:

while (!feof(pfile)) { 

        PcbPtr p = createnullPcb();
        fscanf(pfile, "%d,%d,%d,%d,%d,%d,%d,%d", &p->arrivaltime, &p->priority, &p->remainingcputime, 
        &p->memalloc, &p->pr,  &p->sc, &p->mo, &p->cd);
        char cwd[1024];
        char *tmp = getcwd(cwd, sizeof(cwd));
        strcat(tmp, "/process");
        p->args[0] = tmp;
        p->args[1] = NULL;

        if (!headi) {
            headi = p;
        } 
        else {
            enqPcb(&headi, p);
        }

    }

Why is this happening? Thanks for any help!

  • 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-05T09:16:00+00:00Added an answer on June 5, 2026 at 9:16 am

    What’s happening is that feof returns true when there was an attempt to read past the end. When you are at the end of your file, but haven’t tried to read anything else yet, feof will return false.

    In simple words: feof does not stand for is at the end of the file, but for has attempted to access past the end of the file.

    Note that when you are at the end of the file and try to read that extra line, fscanf will fail. You could check its return value to see if it was able to read anything.

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

Sidebar

Related Questions

I am having following issue with reading binary file in C. I have read
I'm having an issue reading from a java input stream. I have a buffer
Ok so im having a bit of an issue here. basically Im reading shared
I'm having memory issues while reading video frames from an existing video chosen from
Having an issue with traversing in jQuery.. hopfully an easy one..but I'm banging my
I'm opening a CSV file and reading values from it using File.open(filename). So I
I've been having some issues reading an XML file in my 'res' folder and
I'm having an issue reading the below XML document in Chrome - nothing seems
I am having a problem reading back from windows azure table storage: Here is
I am having issues with my code. It is not the issue. It is

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.