Find the answer to your Linux question:
Results 1 to 3 of 3
If I have such an array in PHP Code: <?php $s = array( 'go' => array('walk', 'travel', 'perambulate'), 'get' => array('take', 'swipe', 'yoink', 'pocket') ); ?> How to I replicate ...
  1. #1
    Trusted Penguin elija's Avatar
    Join Date
    Jul 2004
    Location
    Either at home or at work or down the pub
    Posts
    2,300

    Convert simple PHP array to c

    If I have such an array in PHP

    Code:
    <?php
        $s = array(
            'go' => array('walk', 'travel', 'perambulate'),
            'get' => array('take', 'swipe', 'yoink', 'pocket')
        );
    ?>
    How to I replicate that in c?

    I seem to have it a brick wall with this one
    If we hit that bullseye, the rest of the dominoes will fall like a house of cards. Checkmate! (Zapp Brannigan)


    My new blog. It's probably not as good as I think it is.

  2. #2
    Trusted Penguin Cabhan's Avatar
    Join Date
    Jan 2005
    Location
    Seattle, WA, USA
    Posts
    3,230
    So, of course, this is not what is called in C an array: it is a dictionary or a hash map. It maps strings to arrays of strings.

    So first, you need access to a hash map implementation. It's not incredibly difficult to implement your own, but it is a bit of a pain. I have used uthash before on many occasions:
    uthash User Guide

    They also provide a linked list implementation (utlist) that may be a good replacement for your string arrays if they are better represented as linked lists.

    Anyway, hopefully that documentation makes sense to you. Let me know if I can help with anything else.
    DISTRO=Arch
    Registered Linux User #388732

  3. #3
    Trusted Penguin elija's Avatar
    Join Date
    Jul 2004
    Location
    Either at home or at work or down the pub
    Posts
    2,300
    Well, that means going back into K&R as I haven't met structs yet. I was wondering when I'd need to do some more reading.

    Thanks.
    If we hit that bullseye, the rest of the dominoes will fall like a house of cards. Checkmate! (Zapp Brannigan)


    My new blog. It's probably not as good as I think it is.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...