type casting

This is a discussion on type casting within the C Programming forums, part of the General Programming Boards category; Hi all, Sorry for the stupid question... but I havn't used C very often... How do I convert a string ...

  1. #1
    Registered User
    Join Date
    Oct 2007
    Posts
    11

    Question type casting

    Hi all,
    Sorry for the stupid question... but I havn't used C very often...
    How do I convert a string into float?
    THANKS!!!
    Liat.

  2. #2
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,238
    Quote Originally Posted by liats80 View Post
    Hi all,
    Sorry for the stupid question... but I havn't used C very often...
    How do I convert a string into float?
    THANKS!!!
    Liat.
    Many possibilities. sscanf(), strtod(), strtof(), atof() ...

  3. #3
    Registered User
    Join Date
    Oct 2007
    Posts
    11
    Thanks!!!
    I tried atof() and that seems to work fine.
    Any major resons to use something else? (are there advantages for using the others?)
    Thanks again!
    Liat.

  4. #4
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,211
    strtod() and strtof() allow you to detect if the string isn't a double or float respectively and be able to write a complicated routine to figure out how you want to proceed.

    sscanf() has more or less the same limitations of scanf(). It allows some error handling but not as much as strtod() or strtof().

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. What dose this type casting mean??
    By zhoufanking in forum C Programming
    Replies: 4
    Last Post: 06-11-2008, 06:09 AM
  2. Replies: 0
    Last Post: 03-20-2008, 07:59 AM
  3. pointer to array of objects of struct
    By undisputed007 in forum C++ Programming
    Replies: 12
    Last Post: 03-02-2004, 03:49 AM
  4. Erros in Utility Header File
    By silk.odyssey in forum C++ Programming
    Replies: 4
    Last Post: 12-22-2003, 05:17 AM
  5. help with simple type casting problem
    By Jeremy_S in forum C Programming
    Replies: 2
    Last Post: 02-27-2002, 11:38 AM

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