y won't \b work??

This is a discussion on y won't \b work?? within the C Programming forums, part of the General Programming Boards category; Code: fprintf(write, "\b"); if i do this, the program prints an unknown character in the file....anyone know how to get ...

  1. #1
    Registered User Commander's Avatar
    Join Date
    Sep 2001
    Posts
    804

    y won't \b work??

    Code:
    fprintf(write, "\b");
    if i do this, the program prints an unknown character in the file....anyone know how to get around this so the prog actually deletes a character from the end of the file?
    thankx
    oh i'm sorry! i didn;t realize my fist was rushing to meet ur face!

    MSN :: commander_android@hotmail.com []*[]

  2. #2
    Unleashed
    Join Date
    Sep 2001
    Posts
    1,765
    The world is waiting. I must leave you now.

  3. #3
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,546
    > prog actually deletes a character from the end of the file
    Yeah, you open the file for reading, and open another one for writing, then you copy all the chars except the last one from one to the other.

  4. #4
    Registered User Commander's Avatar
    Join Date
    Sep 2001
    Posts
    804
    thnx salem, I'm not really sure how to do it, but i'll figure it out! I think

    to shadow...thankx for the site! it has everythink!
    oh i'm sorry! i didn;t realize my fist was rushing to meet ur face!

    MSN :: commander_android@hotmail.com []*[]

  5. #5
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231

    Re: y won't \b work??

    Originally posted by Commander
    ... so the prog actually deletes a character from the end of the file?
    Just out of interest, why would you want to delete the last byte from the file?
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  6. #6
    Registered User Commander's Avatar
    Join Date
    Sep 2001
    Posts
    804
    I'm trying to write a program that writes what the user types in a file.....so if they press backspace deleting a character, I want to delete that character that has been writen in the file when the user typed it....I'm attaching the code so u could look over....


    PS: when done entering, press esc to exit....
    Attached Files Attached Files
    oh i'm sorry! i didn;t realize my fist was rushing to meet ur face!

    MSN :: commander_android@hotmail.com []*[]

  7. #7
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,856
    AFAIK

    if you use strings like this

    "Strings in quotes have a null terminator added."

    in functions it will add a terminator '\0' to the end. This could be your character. Black square I think.
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  8. #8
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    At present your code reads 1 character from the keyboard, then opens/writes to/closes the file.

    It would be better to buffer the input, say one line at a time, then write out when your buffer is considered full. That way you can remove unwanted characters from the buffer easily.

    Also, try storing the FILE* in the calling function and pass it as a parameter to the "write" function. That way you only need to open the file once.

    Also, try not to confuse your compiler (and me!), a C program has a .c extension, cpp is for C++
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  9. #9
    Registered User Commander's Avatar
    Join Date
    Sep 2001
    Posts
    804
    Originally posted by Hammer
    Also, try storing the FILE* in the calling function and pass it as a parameter to the "write" function. That way you only need to open the file once.
    Could you give an example of how to do that because I'm confuced

    Originally posted by Hammer
    Also, try not to confuse your compiler (and me!), a C program has a .c extension, cpp is for C++
    I never wirte the extension...the borland writes it for me...it's my slave
    oh i'm sorry! i didn;t realize my fist was rushing to meet ur face!

    MSN :: commander_android@hotmail.com []*[]

  10. #10
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    Originally posted by Hammer
    Also, try storing the FILE* in the calling function and pass it as a parameter to the "write" function. That way you only need to open the file once.

    ...... Could you give an example of how to do that because I'm confuced
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    
    int SaveToFile(char *, FILE *);
    
    int main(void)
    {
    	FILE *fp;
    	char stuff[] = "This is a line of text\n";
    	int rc;
    	
    	if ((fp = fopen("data.dat", "w")) == NULL)
    	{
    		perror ("data.dat");
    		return (1);
    	}
    	
    	rc = SaveToFile(stuff, fp);
    	
    	fclose (fp);
    	
    	if (rc == -1)
    		return (EXIT_FAILURE);
    	else
    		return (EXIT_SUCCESS);
    }
    	
    	
    int SaveToFile(char *string, FILE *fp)
    {
    	if (fputs(string, fp) == EOF)
    	{
    		perror ("Write Failed");
    		return (-1);
    	}
    	return (0);
    }
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  11. #11
    Registered User Commander's Avatar
    Join Date
    Sep 2001
    Posts
    804
    thankx hammer! really appreciate ur help.
    oh i'm sorry! i didn;t realize my fist was rushing to meet ur face!

    MSN :: commander_android@hotmail.com []*[]

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. strcmp returning 1...
    By Axel in forum C Programming
    Replies: 12
    Last Post: 09-08-2006, 07:48 PM
  2. getline() don't want to work anymore...
    By mikahell in forum C++ Programming
    Replies: 7
    Last Post: 07-31-2006, 10:50 AM
  3. Why don't the tutorials on this site work on my computer?
    By jsrig88 in forum C++ Programming
    Replies: 3
    Last Post: 05-15-2006, 10:39 PM
  4. fopen();
    By GanglyLamb in forum C Programming
    Replies: 8
    Last Post: 11-03-2002, 11:39 AM
  5. DLL __cdecl doesnt seem to work?
    By Xei in forum C++ Programming
    Replies: 6
    Last Post: 08-21-2002, 04:36 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21