how to spot a failure in scanf??

This is a discussion on how to spot a failure in scanf?? within the C Programming forums, part of the General Programming Boards category; i know that it returns the number of variable that it inputed correctly by its format. but i want that ...

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

    how to spot a failure in scanf??

    i know that it returns the number of variable that it inputed correctly by its format.
    but i want that if it will input 3 variables correctly and the 4th is wrong
    then it will return 3.
    so i dont know if the input is wrong or not
    ??

  2. #2
    Super Moderator
    Join Date
    Sep 2001
    Posts
    4,913
    i know that it returns the number of variable that it inputed correctly by its format.
    but i want that if it will input 3 variables correctly and the 4th is wrong
    then it will return 3.
    I don't read any difference there

  3. #3
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    So you're saying that scanf works exactly the way you want it to. What exactly is the question?

  4. #4
    Banned
    Join Date
    Oct 2008
    Posts
    1,535
    my question is how to know by the return value of scanf
    if it failed or not
    ??

  5. #5
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    I think they want to know:
    Code:
    x = scanf("%d %f %s", &a, &b, c );
    if somehow a gets filled, and c gets filled, but not b, and it returns 2, which ones are valid and which ones aren't.

    That's my guess at what they're asking. In which case, the answer would be: It wouldn't. It would return 1 instead of 2, because it would stop matching scan patterns once it fails to match one of them.


    Quzah.
    Hope is the first step on the road to disappointment.

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, 07:35 AM
  2. DNS Query
    By Simpsonia in forum Networking/Device Communication
    Replies: 1
    Last Post: 04-24-2006, 12:42 AM
  3. Replies: 2
    Last Post: 02-20-2005, 12:48 PM
  4. scanf issue
    By fkheng in forum C Programming
    Replies: 6
    Last Post: 06-20-2003, 07:28 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

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