Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.
Hi all, please see this major site announcement: https://www.boards.ie/discussion/2058427594/boards-ie-2026

stupid c casting question

  • 26-10-2004 09: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,033 ✭✭✭lynchie


    inet_ntoa function will convert it to a string.


Advertisement
Advertisement