Thread: Converting char * to float using sscanf()

  1. #1
    Registered User
    Join Date
    Jan 2005

    Converting char * to float using sscanf()

    Is it possible to convert char * to float using sscanf()? I tried this but it doesn't work.
    #include <stdio.h>
    int main()
        float number;
        char price[] = "49.99";
        sscanf(price, "%lf", number);
        printf("%lf", number);
        return 0;

  2. #2
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    sscanf(price, "%f", &number);
    printf("%f", number);

    and if you're interested:
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    Or even add the compiler option
    gcc -Wall
    if you're using gcc/dev-c++/mingw/cygwin
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. newbie needs help with code
    By compudude86 in forum C Programming
    Replies: 6
    Last Post: 07-23-2006, 08:54 PM
  2. multiple file loading. so fruturated! help!
    By psychopath in forum Game Programming
    Replies: 5
    Last Post: 05-09-2005, 05:13 PM
  3. Passing structures... I can't get it right.
    By j0hnb in forum C Programming
    Replies: 6
    Last Post: 01-26-2003, 11:55 AM
  4. String sorthing, file opening and saving.
    By j0hnb in forum C Programming
    Replies: 9
    Last Post: 01-23-2003, 01:18 AM
  5. Strings are V important...
    By NANO in forum C++ Programming
    Replies: 15
    Last Post: 04-14-2002, 11:57 AM