Thread: scanf

  1. #1
    Registered User
    Join Date
    Jan 2003
    Posts
    115

    scanf

    how would i be able to read in two numbers at a time from input with scanf?

    i tried scanf( "%d %d", &x &y ) but it doesnt work like how i want it to.

    i want to read in like:
    100 22
    23 33
    44 55

    so the first row of numbers would be equivalent to one group.
    there are only 10 people in the world, those who know binary and those who dont

  2. #2
    Registered User
    Join Date
    Jan 2003
    Posts
    115
    sorry

    while ( scanf( "%d %d", &x, &y ) == 1 )

    so i want to end it with a crtl-D
    there are only 10 people in the world, those who know binary and those who dont

  3. #3
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    >>while ( scanf( "%d %d", &x, &y ) == 1 )
    scanf() returns the number of successfully read variables, so in your example the desired return code is 2, not 1.

    >>while ( scanf( "%d %d", &x, &y ) == 2 )
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. scanf() consideres useless
    By Snafuist in forum C Programming
    Replies: 15
    Last Post: 02-18-2009, 08:35 AM
  2. Help with a basic scanf procedure.
    By killpoppop in forum C Programming
    Replies: 9
    Last Post: 11-03-2008, 04:39 PM
  3. Replies: 2
    Last Post: 02-20-2005, 01:48 PM
  4. Scanf and integer...
    By penny in forum C Programming
    Replies: 3
    Last Post: 04-24-2003, 06:36 AM
  5. scanf - data is "put back" - screws up next scanf
    By voltson in forum C Programming
    Replies: 10
    Last Post: 10-14-2002, 04:34 AM