Thread: scanning in with gets() but not over inputing

  1. #1
    Registered User
    Join Date
    Nov 2001
    Posts
    32

    Question scanning in with gets() but not over inputing

    Dear All,

    I am using Borlands C++ V3 DOS compiler for writing a C programmes.

    I am acquainted with scanf() and the use of scan sets. I have used scan sets to define which
    letters, numbers and symbols I want to scan in at the command line. This is very useful
    because a blank space can be included in the scan set so I can scan in words and not just one
    word. Also I can control the scanning in so that over input (If there is such a term) does not
    occur. For example if a had a declaration:
    char word[6]
    I could scan it in with:
    scanf(?%5s?, word);
    So if I typed 6 or more characters an error could not occur.

    The shorter or easier way is to use gets(). I have used this often as well. It automatically
    allows a space between words. One thing I have not achieved with gets() is limiting the
    scanning in to a determined number of characters. For example if a had a declaration:
    char word[6]
    I could scan it in with:
    gets(word);
    But if I typed 6 or more characters then an error could occur.

    I want to use gets() because I do not want to define very long scan sets that would be needed
    to allow most letters, numbers and characters as well as spaces to be scanned in. However I
    do not know if I can limit the scanning in the same way as scanf() does.

    Is this possible ?

    Any help appreciated

    Stephanos

  2. #2
    Registered User
    Join Date
    Nov 2001
    Posts
    32

    gets etc

    Dear Salem

    An excellent solution. This has broardened my knowledge as the idea did not occur to me even though I have used fgets() with files.

    I changed the stream/pointer at end for "stdin" and this works.

    Thanks you

    Stephanos

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Scanning a list?
    By scarlet00014 in forum C Programming
    Replies: 4
    Last Post: 10-15-2008, 03:25 PM
  2. scanning a network
    By Morbo in forum Linux Programming
    Replies: 3
    Last Post: 10-08-2005, 11:41 AM
  3. scanning in character string
    By zackboll in forum C Programming
    Replies: 12
    Last Post: 11-24-2004, 02:18 AM
  4. port scanning
    By HEADSH(+)T in forum C++ Programming
    Replies: 4
    Last Post: 04-23-2004, 02:44 AM
  5. stopping some scanning
    By aoe in forum C Programming
    Replies: 4
    Last Post: 06-09-2002, 01:50 PM