Thread: Ruby to C help

    #1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2008
    Posts
    10
    Rep Power
    0

    Ruby to C help


    Hi,

    First time post, hopefully this won't hurt too bad...
    I have the following Ruby function,

    def convert(num)
    return [num].pack("N")[1,3]
    end


    My question is what would the equivalent C function of this be?
    More specifically I have an idea of what it does, but I'm not completely sure.

    Any and all help would be appreciated.

    -Arbituator
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2006
    Location
    New Jersey
    Posts
    219
    Rep Power
    137
    What that function does is converts an ASCII code to a character. You can also do this in Ruby with simply "num.chr".

    In C, you don't need a function to do this, you can cast num to a character:
    C Code:
    (char)num


    Note, however, that this C "equivalent" returns a char, not a string.

IMN logo majestic logo threadwatch logo seochat tools logo