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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T01:17:08+00:00 2026-06-08T01:17:08+00:00

I am attempting to write a bittorrent client. In order to parse the file

  • 0

I am attempting to write a bittorrent client. In order to parse the file etc. I need to read a torrent file into memory. I have noticed that fread is not reading the entire file into my buffer. After further investigation it appears that whenever the symbol shown below is encountered in the file, fread stops reading the file. Calling the feof function on the FILE* pointer returns 16 indicating that the end of file has been reached. This occurs no matter where the symbol is placed. Can somebody explain why this happens and any solutions that may work.

The symbol is highlighted below:

enter image description here

Here is the code that does the read operation:

char *read_file(const char *file, long long *len){
struct stat st;
char *ret = NULL;
FILE *fp;

//store the size/length of the file
if(stat(file, &st)){
    return ret;
}
*len = st.st_size;

//open a stream to the specified file
fp = fopen(file, "r");
if(!fp){
    return ret;
}

//allocate space in the buffer for the file
ret = (char*)malloc(*len);
if(!ret){
    return NULL;
}

//Break down the call to fread into smaller chunks
//to account for a known bug which causes fread to
//behave strangely with large files

//Read the file into the buffer
//fread(ret, 1, *len, fp);
if(*len > 10000){
    char *retTemp = NULL;
    retTemp = ret;
    int remaining = *len;
    int read = 0, error = 0;
    while(remaining > 1000){
        read = fread(retTemp, 1, 1000, fp);
        if(read < 1000){
            error = feof(fp);
            if(error != 0){
                printf("Error: %d\n", error);
            }
        }
        retTemp += 1000;
        remaining -= 1000;
    }
    fread(retTemp, 1, remaining, fp);
} else {
    fread(ret, 1, *len, fp);
}

//cleanup by closing the file stream
fclose(fp);

return ret;
}

Thank you for your time 🙂

  • 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-08T01:17:10+00:00Added an answer on June 8, 2026 at 1:17 am

    Your question is oddly relevant as I recently ran into this problem in an application here at work last week!

    The ASCII value of this character is decimal 26 (0x1A, \SUB, SUBSTITUTE). This is used to represent the CTRL+Z key sequence or an End-of-File marker.

    Change your fopen mode (“In [Text] mode, CTRL+Z is interpreted as an end-of-file character on input.”) to get around this on Windows:

    fp = fopen(file, "rb"); /* b for 'binary', disables Text-mode translations */
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been attempting to write a VBA Script that can parse out other
I have been attempting to write some routines to read RSS and ATOM feeds
Attempting to write a line to a text file in Python 2.7, and have
When attempting to write/read cookies that have brackets in the name, it seems like
I am attempting to write an Android app which will allow me to read
I am attempting to write my first Dynamics Crm 2011 plugin. I have therefore
i'm attempting to write the result of the $x = [System.Net.Dns]::GetHostAddresses($name) statement into my
I am attempting to write a file to external storage in android. I keep
I'm attempting to write an ASCII null character (nul) to a file from a
Im attempting to write a push server for the iPhone in C#. I have

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.