Thread: Limitting User Input

  1. #1
    Registered User
    Join Date
    Aug 2007
    Posts
    5

    Limitting User Input

    Is it possible to "limit" how many characters a user can input in a program?
    Eg. A user can only input upto 5 characters, after 5 characters, a user has only two choices.
    Pressing the return key or erasing one or more characters to replace them. I hope you're getting my point. XD

    Something like this on HTML:

    Code:
    <INPUT TYPE=text NAME=mic_test SIZE=15 VALUE="Test" MAXLENGTH=10>
    Last edited by doomsweek; 08-06-2007 at 11:46 PM.

  2. #2
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    Yes and no, with something like a curses library you could.
    Check out PDCurses or ncurses.

  3. #3
    Registered User
    Join Date
    Aug 2007
    Posts
    5
    Not possible with the libraries that came in with dev-cpp ?

  4. #4
    Registered User
    Join Date
    Oct 2001
    Posts
    2,129
    you can't control the input, but you can control how many characters are accepted into the program with the width specifier.

    http://www.cplusplus.com/reference/c...dio/scanf.html

  5. #5
    System Novice siavoshkc's Avatar
    Join Date
    Jan 2006
    Location
    Tehran
    Posts
    1,246
    For a console program you can use <conio.h> and use getche() or _getche(). Or you can use an API.
    Learn C++ (C++ Books, C Books, FAQ, Forum Search)
    Code painter latest version on sourceforge DOWNLOAD NOW!
    Download FSB Data Integrity Tester.
    Siavosh K C

  6. #6
    Registered User
    Join Date
    Oct 2001
    Posts
    2,129
    fyi, conio.h is not standard C.

  7. #7
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    Use PDCurses/ncurses over conio.h!
    Mainly because it's more portable and supported across an array of compilers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. About aes
    By gumit in forum C Programming
    Replies: 13
    Last Post: 10-24-2006, 03:42 PM
  2. SSH Hacker Activity!! AAHHH!!
    By Kleid-0 in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 03-06-2005, 03:53 PM
  3. Nested Structures - User Input
    By shazg2000 in forum C Programming
    Replies: 2
    Last Post: 01-09-2005, 10:53 AM
  4. ~ User Input script help~
    By indy in forum C Programming
    Replies: 4
    Last Post: 12-02-2003, 06:01 AM
  5. Getting user input for filename loop
    By jpchand in forum C++ Programming
    Replies: 1
    Last Post: 09-16-2003, 06:37 AM