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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T23:33:55+00:00 2026-05-23T23:33:55+00:00

How do i remove the white spaces in my text file ? The reason

  • 0

How do i remove the white spaces in my text file ? The reason to work behind it, my colleague, he has lots of text files with huge amount of white spaces between them. Its getting harder for him to remove them by hitting backspace.So what i planned is to write a code to that.And i was successful upto 99%. Check up the below code that i have written.

#include<stdio.h>

int main()
{
    int b;
    char array[100];
    gets(array); \\ file name to be given here
    FILE *P;
    FILE *T;
    P=fopen(array,"r");
    T=fopen("./duplicate.txt","w");
    for(;(b=getc(P))!=EOF;)
    {
        if(b==32)
        {
            fputc(b,T);
            me:
            b=getc(P);
            if(b==32)
            goto me;
        }
        fputc(b,T);
    }
}

The code working perfect but the thing I did it, by creating a duplicate of original text file.But i dont want to make duplicate , I want to rewrite to the original file itself. I tried it to the original text file.But some where its going wrong.

I have the algorithm how to approach it like saving the strings and writing them back to file but i think that is not the efficient approach. And guys i have a doubt

fputs("\b",filepointer);

will these create a backspace I suppose no is the answer. because its writing the backspace character not performing the backspace operation.But i think there is a function ungetc() will it work here.Any ideas would be rewarded.Thank you

  • 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-23T23:33:56+00:00Added an answer on May 23, 2026 at 11:33 pm

    While I would agree other posters there are much better choices then C for this, and you have several security and design problems, I’m going to answer your original question.


    You cannot directly edit the file in place, because you are not simply changing what is there – you are changing the length and the structure; because of this, at some point you will be copying: either to memory or to a second file.
    malloc() a buffer that is the size of the original file (because worst case it cannot be more, best case is much smaller) and read your characters in to memory. When done, fopen() your original file with the “w” flag and write everything back. I would normally recommend you make a copy and then delete-rename, but that appears to not be what a solution you are willing to accept based on your other comments.
    A warning, though: during the time you have reopened your file and the time you have written everything back, you risk losing data.

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

Sidebar

Related Questions

I have written ashx which merges and remove white-spaces for javascript and css contents.
I am loading a text file (which contains many lines, some containing spaces or
How can I remove the spaces, tab characters, new line characters between > and
Anyone know how to remove white space between strings for all browsers? This works
Is there any way in VB.NET to remove all of the whitespaces between tags
How can I remove those annoying Mac OS X .DS_Store files from a Git
I have to parse a tab-delimited text file with Ruby to extract some data
I have a long regular expression that parses a text file into various match
Array( [1] => put returns (between) paragraphs [2] => (for) linebreak (add) 2 spaces
Is there a reason why the text content of a WPF button is appearing

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.