Thread: scanf() value return

  1. #1
    Registered User Spectrum48k's Avatar
    Join Date
    May 2002
    Posts
    66

    scanf() value return

    when scanf() succesfully reads an integer it returns a value of 1. what if its not an int. what if its a float value. will it still return a 1?

    thanx..

  2. #2
    Unleashed
    Join Date
    Sep 2001
    Posts
    1,765
    The world is waiting. I must leave you now.

  3. #3
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    >will it still return a 1?
    Yes, it probably stops scanning once it sees a decimal point. If you need to know whether a float was entered, either:

    read in the number as a string, check for a decimal point, then convert it using atoi

    or

    read in the number as a double, and use modf() to see if there is a fractional part.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. 6 measly errors
    By beene in forum Game Programming
    Replies: 11
    Last Post: 11-14-2006, 11:06 AM
  2. Another weird error
    By rwmarsh in forum Game Programming
    Replies: 4
    Last Post: 09-24-2006, 10:00 PM
  3. DirectInput help
    By Muphin in forum Game Programming
    Replies: 2
    Last Post: 09-10-2005, 11:52 AM
  4. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM
  5. OpenGL and Windows
    By sean345 in forum Game Programming
    Replies: 5
    Last Post: 06-24-2002, 10:14 PM