deletes

This is a discussion on deletes within the C Programming forums, part of the General Programming Boards category; Can anyone help ?. Is there any way or function that allows a user to use the arrow key to ...

  1. #1
    hen
    Guest

    Unhappy deletes

    Can anyone help ?. Is there any way or function that allows a user to use the arrow key to go back and delete and replace data before enter is pressed ?. I am writing a program that requires a lot of user input but I can't find a way to let the user correct mistakes as they happen. This may sound a simple problem but I have run out of ideas.

  2. #2
    Registered User Draco's Avatar
    Join Date
    Apr 2002
    Posts
    463
    are you planning to use something like gets() for large entries? gets() allows you to use delete in the manner you describe (for me at least).

  3. #3
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    gets() is bad.... use fgets() instead.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  4. #4
    Registered User Draco's Avatar
    Join Date
    Apr 2002
    Posts
    463
    my bad I was raised on gets() and have never used fgets() yet.

  5. #5
    hen
    hen is offline
    Registered User
    Join Date
    Jun 2002
    Posts
    16
    Most of the entered data are numbers, so I have been using scanf to store them in integers or floats. The program works fine but I would still try to let the user correct any wrongly pressed keys as they go. I have tried to use gets and fgets but I am still unable to change any data once it is keyed in ( before I press enter). I would really appreciate any help with this .
    Last edited by hen; 08-16-2002 at 01:46 PM.

  6. #6
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    ... but I am still unable to change any data once it is keyed in ( before I press enter).
    If you're using fgets() you should be able to use the backspace key to delete text you've entered. Doesn't this work for you? What OS, compiler etc?
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  7. #7
    hen
    hen is offline
    Registered User
    Join Date
    Jun 2002
    Posts
    16
    I am using Windows Me and Borland Turbo C++ 4.5 compiler but I am unable to move the curser backwards after keying in any data
    Last edited by hen; 08-17-2002 at 07:33 AM.

  8. #8
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    Windows uses buffered input, what you want should be possible quite easily with fgets. Try this code and see if you still have the same problem, it may just be that you're not doing it right.
    Code:
    #include <stdio.h>
    
    int main ( void )
    {
      char buffer[BUFSIZ];
      if ( fgets ( buffer, sizeof buffer, stdin ) != NULL )
        (void)puts ( buffer );
      return 0;
    }
    I can type "This is a test" then before pressing return, I can use the arrow keys to move back and change it to "This is a neat test." and once I hit return the most recent changes are printed.

    -Prelude
    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How write class like vector that deletes self?
    By 6tr6tr in forum C++ Programming
    Replies: 7
    Last Post: 05-04-2008, 11:46 AM
  2. Pleas take a look & give a critique
    By sh3rpa in forum C++ Programming
    Replies: 14
    Last Post: 10-19-2007, 10:01 PM
  3. Visual Studio designer deletes my user control
    By bennyandthejets in forum C# Programming
    Replies: 1
    Last Post: 05-06-2005, 07:44 AM

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