Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

String Question in C

  • 30-05-2005 07: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, Registered Users 2 Posts: 16,415 ✭✭✭✭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, Registered Users 2 Posts: 16,415 ✭✭✭✭Trojan


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


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


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


  • Registered Users, Registered Users 2 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