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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T07:45:28+00:00 2026-05-30T07:45:28+00:00

I am reading a plain text from a file – by lines, with a

  • 0

I am reading a plain text from a file – by lines, with a following function:

int readline(FILE *in, char * buf) {
char c;
buf[0]='\0';
for (int i=0; i<BUFSIZ-1; i++) {
    fread(&c,1,1,in);
    if (ferror(in)) return 1; 
    if (feof(in)) break;
    buf[i]=c; 
    if (c=='\n') break;
    }
    if (buf[BUFSIZ-1]!='\0') return 1;
    return 0;
}

It reads correctly 28816 characters, and then the trouble starts.
Instead of reading the next four characters:

' ' 'f' 'o' 'r'

it reads the weird thing:

'\x01' '\0' '\0' '\0'

After that, it reads everything correctly until 33080 character.
Instead of reading next 12 characters correctly, it reads three sequences:

'\x01' '\0' '\0' '\0' '\x01' '\0' '\0' '\0' '\x01' '\0' '\0' '\0'

Then, it reads everything correctly again, until certain point.

There weren’t neither (ferror(in)) nor (feof(in)) condition true when this problem occurs.

Do you have any ideas about the cause of this problem?

  • 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-30T07:45:30+00:00Added an answer on May 30, 2026 at 7:45 am

    It doesn’t look like random data – it is the byte sequence for an integer value of 1 (assuming x86 or similar CPU).

    I would expect one of two situations:

    1) you’re writing off the end of the buffer, and something else is using the same memory

    2) somewhere else in your program, you’re writing off the end of another array into the memory used by the buffer.

    From the comments, I see you’ve debugged it, seemingly ruling out both options. I wonder whether optimisation was disabled when you were debugging? I’ve had tricky experiences debugging an optimised binary in the past.

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

Sidebar

Related Questions

am [writing reading] from a plain text file usernames and passwords, but its an
I'm pro-grammatically reading emails from Exchange 2010 that have been sent in plain text.
I have a plain text file which have the list of countries as follows.
I need to write a series of matrices out to a plain text file
I am using following c code #include <fcgi_stdio.h> /* * */ int main(int argc,
I'm reading an article from this website , but when i run the code
I have this code. It's from the Zend Reading Mail example. $message = $mail->getMessage(1);
I am reading the tutorial about Receiving Mail . I updated the app.yaml file
i have been working on this text extraction project of various file extensions, but
I want to read a text file which has text as follows(sample) abc ip-32-56-198-18.com

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.