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
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

stupid c casting question

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


    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 Posts: 2,013 ✭✭✭lynchie


    inet_ntoa function will convert it to a string.


Advertisement