How to use atoi with an int and malloc? : <p>When I try and use atoi with an int and malloc I get a bunch of errors and key is given the wrong value, what am I doing wrong?</p>

<pre><code>#include &lt;stdio.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;string.h&gt;

struct arguments {
    int key;
};

void argument_handler(int argc, char **argv, struct arguments *settings);

int main(int argc, char **argv) {
    argv[1] = 101; //makes testing faster
    struct arguments *settings = (struct arguments*)malloc(sizeof(struct arguments));
    argument_handler(argc, argv, settings);
    free(settings);
    return 0;
}

void argument_handler(int argc, char **argv, struct arguments *settings) {
    int *key = malloc(sizeof(argv[1]));
    *key = argv[1];
    settings-&gt;key = atoi(key);
    printf("%d\n", settings-&gt;key);
    free(key);
}
</code></pre>
