fscanf %s or %d integer input space char stop question...

This is a discussion on fscanf %s or %d integer input space char stop question... within the C Programming forums, part of the General Programming Boards category; i want fscanf to read an integer but to stop when space char appears.. Code: fscanf(room,%10s%,&id); i read that %s ...

  1. #1
    Banned
    Join Date
    Oct 2008
    Posts
    1,535

    fscanf %s or %d integer input space char stop question...

    i want fscanf to read an integer
    but to stop when space char appears..

    Code:
    fscanf(room,%10s%,&id);
    i read that %s means stop when there is whitespace

    but on the scanf command i knew
    that %s ment read a string

    how to read the in put as an integer and stop when there is
    a space
    ??

  2. #2
    Banned
    Join Date
    Oct 2008
    Posts
    1,535
    and if ill write %d then it will get it as integer
    but wont stop at space char
    how to read the in put as an integer and stop when there is
    a space
    ??

  3. #3
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    I'm sure it will stop at a space - are you sayiong that if you enter 123 456 to scanf, you get the integer value 123456? Change your compiler!

    --
    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
    Banned
    Join Date
    Oct 2008
    Posts
    1,535
    why it stops at space with %d

    the manual says %s means read till you get white space

    there is no such thing for %d

    ??

  5. #5
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,758
    Quote Originally Posted by transgalactic2
    why it stops at space with %d

    the manual says %s means read till you get white space

    there is no such thing for %d
    Whitespace is not considered part of a number.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  6. #6
    Banned
    Join Date
    Oct 2008
    Posts
    1,535
    thanks

    %d stops at white space too

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. memory issue
    By t014y in forum C Programming
    Replies: 2
    Last Post: 02-20-2009, 11:37 PM
  2. Link List math
    By t014y in forum C Programming
    Replies: 17
    Last Post: 02-20-2009, 05:55 PM
  3. load gif into program
    By willc0de4food in forum Windows Programming
    Replies: 14
    Last Post: 01-11-2006, 09:43 AM
  4. How do i un-SHA1 hash something..
    By willc0de4food in forum C Programming
    Replies: 4
    Last Post: 09-14-2005, 05:59 AM
  5. File input question
    By Beast() in forum C Programming
    Replies: 16
    Last Post: 07-09-2004, 03:23 PM

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