restrict input

This is a discussion on restrict input within the C Programming forums, part of the General Programming Boards category; in this line: scanf("%6s", &info); the input is only 6 characters and the program only takes in the first 6 ...

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

    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,246
    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,164
    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, 12: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

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