Thread: restrict input

  1. #1
    Registered User
    Join Date
    Sep 2004
    Posts
    83

    Question restrict input

    in this line:

    scanf("%6s", &info);

    the input is only 6 characters and the program only takes in the first 6 characters.

    however when i go to compile and run the program, i can type as many characters i want. in the program, as i type the input, i don't want to be able to type more than 6 characters.

    can someone give me the code or lead me in that direction?

    i know its possible because in the past i created a program that asks for a username (5 chars) and you can't type more than 5 chars in the line.

    thanks,
    barneygumble742

  2. #2
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    The reason it works that way, is that the console wont flush what the user types in until a carraige return is entered. There are non-standard ways to do what you are asking, but that will depend on platform and compiler.

  3. #3
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,218
    You'll have to use non-buffered input for that.
    If you understand what you're doing, you're not learning anything.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. input redirection
    By sashaKap in forum C Programming
    Replies: 6
    Last Post: 06-25-2009, 01:59 AM
  2. I would love some input on my BST tree.
    By StevenGarcia in forum C++ Programming
    Replies: 4
    Last Post: 01-15-2007, 01:22 AM
  3. About aes
    By gumit in forum C Programming
    Replies: 13
    Last Post: 10-24-2006, 03:42 PM
  4. Structure and Linked List User Input Question
    By kevndale79 in forum C Programming
    Replies: 16
    Last Post: 10-05-2006, 11:09 AM
  5. Help with Input Checking
    By Derek in forum C Programming
    Replies: 7
    Last Post: 06-17-2003, 03:07 AM