Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

String Question in C

Options
  • 30-05-2005 7:18pm
    #1
    Closed Accounts Posts: 680 ✭✭✭


    In C, if i have a char array char string1[] = "532432" how do i

    1) convert that string to a double or float

    2) convert that double or float back to a string?

    atof doesn't seem to work for me in the way its described online.


Comments

  • Registered Users Posts: 16,413 ✭✭✭✭Trojan


    What does:
    double foo; foo = atof(string1); printf("foo=\"%8.2f\"", foo);
    
    give you?

    In what way is atof() not working compared to man pages?


  • Registered Users Posts: 16,413 ✭✭✭✭Trojan


    Forgot to mention sprintf()/snprintf() for reversal.


  • Registered Users Posts: 4,003 ✭✭✭rsynnott


    By the way, in general, it's better to avoid using floats; most (all?) library functions use doubles.


  • Registered Users Posts: 4,276 ✭✭✭damnyanks


    Didn;t know that quite handy.

    I lurve c its quite nice indeed also eclipse stinks its too bloaty.

    Indeed


Advertisement