• C

How do you go back a space when writing to a file?

Here's the question.......how do you go back a space in the file you are writing to?  When i do

fputc("\b", fpTextOut);  

all that happens is a box gets outputted in the file, but what i want to do is go back a space and write over the previously written text in the file being written to.....

It's not a hard question....please give syntax in the answer. Thanks!
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.


That's occurring because your command really insert the char '\b' into the file. You have to move the file pointer back...

itssookAuthor Commented:
hey neimeyer,

that's right, it worked! Answer the question to get your points!
you can give him points even if he didn't answer.
just click beside his comment
it say "accept comment as answer" or something like this.
10 Tips to Protect Your Business from Ransomware

Did you know that ransomware is the most widespread, destructive malware in the world today? It accounts for 39% of all security breaches, with ransomware gangsters projected to make $11.5B in profits from online extortion by 2019.

>fputc("\b", fpTextOut);  

This will insert the \b character in your file, as niemeyer said.  However, when your file is interpreted (i.e. dumped to the screen), the \b character may actually incite a backspace and the output would reflect this.

However, if you want to remove the char from the actual file, niemeyer's solution is what you want.
/* Assume file name to be read is "file.dat"
 * Assume contents of "file.dat" is (below)
 * 12345
 * Output of program execution is shown below
 * 12
 * File contents now would be
 * 1n345
 * Written to solve your problem
 * Hope it will helps

#include <stdio.h>

void main()
    FILE *fp;
    char input;
    char replace='n';

    if ( (fp = fopen("file.dat","r+b")) == NULL )  /* open file as binary file */
        printf("Error in opening file.\n");
    else { /* file position now at 1st position */
        input = getc(fp); /* file position now at 2nd position after reading */
        input = getc(fp); /* file position now at 3rd position after reading */
        fseek(fp,-1,SEEK_CUR);   /* move file position back to 2nd position */
        fputc(replace,fp);   /* write the replace char to current position */
Hi hongjun!!

I'm missing something or I've already answered this question 7 hours before you?

People here is very smart...  :-)
itssookAuthor Commented:
neimeyer answered first if hee propesed an answer i'd give him the points
You could consider my comment as an answer. But no problems... if it's better for you if I submit an answer... here it is! :-)

Thank you!

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
No offence neimeyer. I only trying to help.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.