Thread: Auto Complete ?

  1. #1
    Registered User
    Join Date
    Nov 2004
    Posts
    6

    Auto Complete ?

    Hi all,
    I am doing a router simulator. and my programming skill is consider the basic of the basic
    I am just wondering, could anyone show me how do i do this,

    on line 1 of the console, i enter "ena"
    on line 1 of the console, i press tab button
    on line 1 of the console, the "ena" become "enable"
    text could still be enter after the enable and the story go on and on ...

    is there a way to do this in C/C++ or had to use MFC ???

    Thanks

  2. #2
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    Ok I have read this, then reread this, still confused i rereread it. Now I'm just going to have to ask; huh?

  3. #3
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Read each keystroke. If tab is entered, search your list of commands for the current buffer. If there is a match, subsitute it for the command. If there is more than one match, subsitute the first. If tab is pressed again, subsitute the second. And so on.

    So all you need to do is:

    1) Have a list of commands.
    2) Read each keystroke as your input loop.
    3) Process input accordingly.


    Quzah.
    Hope is the first step on the road to disappointment.

  4. #4
    Registered User
    Join Date
    Nov 2004
    Posts
    6
    Quote Originally Posted by master5001
    Ok I have read this, then reread this, still confused i rereread it. Now I'm just going to have to ask; huh?
    it is something like the DOS/ UNIX-BASH auto complete. It help you complete the filename.
    let say in red-hat,
    i type adsl-set, press tab, it add "up" to "adsl-set", making it "adsl-setup".
    it is something like that ...

    thanks

  5. #5
    Registered User
    Join Date
    Nov 2004
    Posts
    6
    Quote Originally Posted by quzah
    Read each keystroke. If tab is entered, search your list of commands for the current buffer. If there is a match, subsitute it for the command. If there is more than one match, subsitute the first. If tab is pressed again, subsitute the second. And so on.

    So all you need to do is:

    1) Have a list of commands.
    2) Read each keystroke as your input loop.
    3) Process input accordingly.


    Quzah.

    Ok, get part of it, but still a bit confuse, cause i am not very pro in C. but thanks a lot for ur solution

  6. #6
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    I think you need to be concentrating on the "I am doing a router simulator" part of the problem before wasting a lot of time on making the user interface just a bit more glossy than necessary.

    A program which does routing simulation with the minor inconvenience of having to type "enable" in full is far more preferable than a program which auto completes "ena" to "enable" and then fails to do anything.

  7. #7
    Registered User
    Join Date
    Nov 2004
    Posts
    6
    Quote Originally Posted by Salem
    I think you need to be concentrating on the "I am doing a router simulator" part of the problem before wasting a lot of time on making the user interface just a bit more glossy than necessary.

    A program which does routing simulation with the minor inconvenience of having to type "enable" in full is far more preferable than a program which auto completes "ena" to "enable" and then fails to do anything.
    That is what i think, but then our ~!@#$%^&*( lecturer need us to include this function in it ....
    this is going to be a long long task ....

  8. #8
    Registered User
    Join Date
    Nov 2004
    Posts
    6
    which function can i use? can anyone guide me along ....

  9. #9
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    Use strncmp() to compare the N letters you've typed in so far with an array of complete words which match your commands.
    If that results in a unique match, you can complete the command

  10. #10
    Registered User
    Join Date
    Nov 2004
    Posts
    6
    the problem is i do not have problem dealing with strncmp, however i did have problem dealing with how do i get the input from the buffer directly without pressing tab. i had look at the example in the faqs, but i still can not figure out... what function should i use on this? getchar or getch??

  11. #11
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    What you want to do is entirely OS dependant. There is no standard way to read a keystroke, which is what you need to do. Thus, you'll have to use something like the curses library, if you're using a *nix variant, or some of the old dos routines if you're using DOS, or some of the Windows API functions if you're programming for windows, or ... You see the problem?

    Quzah.
    Hope is the first step on the road to disappointment.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Are auto pointers any good?
    By cunnus88 in forum C++ Programming
    Replies: 3
    Last Post: 04-15-2007, 11:07 AM
  2. Code: An auto expanding array (or how to use gets() safely).
    By anonytmouse in forum Windows Programming
    Replies: 0
    Last Post: 08-10-2004, 12:13 AM
  3. Replies: 14
    Last Post: 04-27-2003, 06:37 PM
  4. Doom Lord engine complete!
    By Leeman_s in forum Game Programming
    Replies: 8
    Last Post: 05-12-2002, 12:44 AM
  5. doom lord engine complete!
    By Leeman_s in forum C++ Programming
    Replies: 4
    Last Post: 04-25-2002, 08:41 PM