Thread: scanf problems

  1. #16
    Registered User ssharish2005's Avatar
    Join Date
    Sep 2005
    Location
    Cambridge, UK
    Posts
    1,732
    I absolutly do not have a clue what where your idea was. But it dint work

    Code:
        int val;    
        while( i++ < count)
        { 
            if( scanf( " %d", &val) == 0 )
    And you literally copied my code with no signature and the comment within if statment could imply only to my code, but will totally be invalid to your version. And you should know why. Perhaps be good idea to remove it.

    ssharish
    Last edited by ssharish2005; 06-16-2011 at 05:23 PM.
    Life is like riding a bicycle. To keep your balance you must keep moving - Einstein

  2. #17
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    I'm not sure why you are using strtol in your version. Also, you can get rid of the function to clear the buffer, and just have scanf do it for you.
    Code:
    scanf( "%*[^\n]%*c" );

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

  3. #18
    Registered User ssharish2005's Avatar
    Join Date
    Sep 2005
    Location
    Cambridge, UK
    Posts
    1,732
    I definitely like your string formatter to clear the buffer too. Well i used strtol to convert the string to an int, as I’m reading string rather than int's. And the OP was after int.

    ssharish
    Last edited by ssharish2005; 06-16-2011 at 05:25 PM.
    Life is like riding a bicycle. To keep your balance you must keep moving - Einstein

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problems with scanf
    By alexkim123 in forum Tech Board
    Replies: 7
    Last Post: 07-08-2010, 05:19 PM
  2. scanf and integer problems
    By jericjones45 in forum C Programming
    Replies: 5
    Last Post: 02-27-2010, 07:12 AM
  3. problems with if() or scanf() i think...
    By nostrum in forum C Programming
    Replies: 5
    Last Post: 07-31-2004, 11:45 AM
  4. Problems with scanf
    By kinghajj in forum C Programming
    Replies: 2
    Last Post: 07-13-2003, 08:53 PM
  5. scanf problems
    By Unregistered in forum C Programming
    Replies: 4
    Last Post: 03-24-2002, 05:33 PM