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

stupid c casting question

Options
  • 26-10-2004 10:54am
    #1
    Registered Users Posts: 2,320 ✭✭✭


    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 Posts: 950 ✭✭✭jessy


    how are you printing it to the screen.


  • Registered Users 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 Posts: 1,994 ✭✭✭lynchie


    inet_ntoa function will convert it to a string.


Advertisement