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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T05:30:43+00:00 2026-05-26T05:30:43+00:00

I am try to write a buffer so I can remove a lot of

  • 0

I am try to write a buffer so I can remove a lot of null “00” characters in a file. The characters are useless and are completely random. They are wreaking havoc on the searcher in the program. The code below compiles but just seems to hang when a file is passed to it. Any suggestions will be helpful.

void ReadFile(char *name)
{
    FILE *dbg;
    char *buffer;
    unsigned long fileLen;

    //Open file
    dbg = fopen(dbg, "w+");
    if (!dbg)
    {
        fprintf(stderr, "Unable to open file %s", name);
        return;
    }

    //Get file length
    fseek(dbg, 0, SEEK_END);
    fileLen = ftell(dbg);
    fseek(dbg, 0, SEEK_SET);

    //Allocate memory
    buffer = (char *)malloc(fileLen+1);
    if (!buffer)
    {
        fprintf(stderr, "Memory error!");
        fclose(dbg);
        return;
    }

    //Read file contents into buffer
    fread(buffer, fileLen, 1, dbg);
    for(i = fileLen-1; i >= 0 && buffer[i] == 0; i--);  
    i++;
    if (i > 0)
    {
        fwrite(buffer, 1, i, dbg);
    }
    fclose(dbg);

    //Do what ever with buffer

    free(buffer);
}
  • 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-26T05:30:44+00:00Added an answer on May 26, 2026 at 5:30 am

    Change

    dbg = fopen(dbg, "w+");
    

    to

    dbg = fopen(name, "w+");
    

    Also, if you want to read the file, change it then write it, you shouldn’t open it with "w+". You should first open the file with "r", read from it, do whatever change you want, then fclose it, then again open it but this time with "w" so that you write over it. After you have opened it in "w"rite mode, you can write the modified buffer back into the file.

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

Sidebar

Related Questions

I try to write KSH script for processing a file consisting of name-value pairs,
I try to write to a large file, but it seems like it does
I'm trying to write a servlet, that can upload a file from client to
I have a piece of C code where I try to write a buffer
I try to write a simple client/server application (all application is a bluetooth service
I try to write a simple Markdown parser in JavaScript. Therefore I want to
I try to write a macro in clojure that sets up a namespace and
I try to write a simple user script to enlarge the picture when you
I try to write the following in latex: \begin{itemize} \item \textbf{insert(element|text)} inserts the element
I try to write :ab in Vim for faster coding but the question 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.