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.

stupid c casting question

  • 26-10-2004 10:54AM
    #1
    Registered Users, Registered Users 2 Posts: 2,323 ✭✭✭


    hey guys,

    I have a newtork ip that is a long int (returned from the ntohl function) in c. When displayed on screen it comes up as hex. i want to display this as a proper ip address, therefore i (think i) need to cast it
    char decimalip [4]
    
    so that i can display each element and put a . between them.

    Any ideas as to how this is done?

    all the best,

    darren


Comments

  • Registered Users, Registered Users 2 Posts: 950 ✭✭✭jessy


    how are you printing it to the screen.


  • Registered Users, Registered Users 2 Posts: 53 ✭✭martinoc


    If all you want to do is print the ip address to the standard out, printf should be able to convert from hex to decimal with the %d placeholder. Casting will not convert the numbers from hex into decimal.


  • Registered Users, Registered Users 2, Paid Member Posts: 2,032 ✭✭✭lynchie


    inet_ntoa function will convert it to a string.


Advertisement