spaces in input

This is a discussion on spaces in input within the C Programming forums, part of the General Programming Boards category; If I'm grabbing a few double variables from the user with scanf, is there some simple way to accept input ...

  1. #1
    Registered User
    Join Date
    Sep 2008
    Posts
    2

    Smile spaces in input

    If I'm grabbing a few double variables from the user with scanf, is there some simple way to accept input with spaces in it? Right now if a number like 1 100 is entered, 1 is stored in double1 and 100 jumps in to double2. I'm wondering how to get 1100 into double 1 even if 1 100 is inputed.

    Thanks

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    How do you know where one double stops and the next double starts, if not by spaces?

  3. #3
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    If you really want to read numbers that have spaces in them, you would have to read the numbers as strings (and then have some other way to determine where one number ends and the next one starts, as tabstop points out), and then process the string to remove the spaces and convert it to double (you can use for example strtod() as a function to convert a string to double).

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  4. #4
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    I do not know the answer to this question, but: if you are in a place where people type 1 100, perhaps your locale allows this when doing strtod.

  5. #5
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by tabstop View Post
    I do not know the answer to this question, but: if you are in a place where people type 1 100, perhaps your locale allows this when doing strtod.
    If that was the case, I'd expect that scanf would also apply that rule.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  6. #6
    Registered User
    Join Date
    Sep 2008
    Posts
    2
    ahh okay, thanks

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Printing Length of Input and the Limited Input
    By dnguyen1022 in forum C Programming
    Replies: 33
    Last Post: 11-29-2008, 03:13 PM
  2. still problems with ceasar shift
    By trevordunstan in forum C Programming
    Replies: 2
    Last Post: 09-14-2008, 01:49 AM
  3. Basic C input output program help
    By trevordunstan in forum C Programming
    Replies: 2
    Last Post: 01-27-2008, 05:41 PM
  4. Custom Made Safe Input Function
    By Beast() in forum C Programming
    Replies: 6
    Last Post: 08-21-2004, 10:19 PM
  5. fgets - user input including spaces
    By MethodMan in forum C Programming
    Replies: 24
    Last Post: 03-12-2004, 06:36 PM

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