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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T00:13:33+00:00 2026-06-14T00:13:33+00:00

I wanted to read bytes from file and then rewrite them. I did like

  • 0

I wanted to read bytes from file and then rewrite them.
I did like so:

FILE *fp;
int cCurrent;
long currentPos;

/* check if the file is openable */
if( (fp = fopen(szFileName, "r+")) != NULL )
{
    /* loop for each byte in the file crypt and rewrite */
    while(cCurrent != EOF)
    {
        /* save current position */
        currentPos = ftell(fp);
        /* get the current byte */
        cCurrent = fgetc(fp);
        /* XOR it */
        cCurrent ^= 0x10;
        /* take the position indicator back to the last position */
        fseek(fp, currentPos, SEEK_SET);
        /* set the current byte */
        fputc(cCurrent, fp);
    }

After executing the code on a file, the size of the file is increasing within an infinite loop.

What is the problem in my code?

  • 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-14T00:13:34+00:00Added an answer on June 14, 2026 at 12:13 am

    You are XOR-ing cCurrent with 0x10 even if it’s equal to EOF. Once you XOR, it’s no longer EOF, so your loop never terminates.

    Make the loop infinite, and exit from the middle when you see an EOF, like this:

    for (;;)  {
        /* save current position */
        currentPos = ftell(fp);
        /* get the current byte */
        if ((cCurrent = fgetc(fp)) == EOF) {
            break;
        }
        /* XOR it */
        cCurrent ^= 0x10;
        /* take the position indicator back to the last position */
        fseek(fp, currentPos, SEEK_SET);
        /* set the current byte */
        fputc(cCurrent, fp);
        /* reset stream for next read operation */
        fseek(fp, 0L, SEEK_CUR);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to read bytes from a wave file into an array. Since the
I'm trying to read data in from a binary file and then store in
I am new to Python and wanted to read a file, which has even
I need to un-read characters from an InputStreamReader . For that purpose I wanted
If I wanted to fill a structure from a binary file, I would use
int bufferSize = 8192; Byte[] buffer = new Byte[bufferSize]; I need to read from
I've read about Single-Page Applications recently and wanted to try one out. After watching
Initial Question Yesterday i read about ECMAScript 5 Object.create() And I wanted to start
I am new to modernizr. I read some documentation on modernizr, and I wanted
Wanted to know if there was a way one could query shelveset details from

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.