stack dump accessing malloc char array

Posted by robUK on Stack Overflow See other posts from Stack Overflow or by robUK
Published on 2010-05-12T08:54:36Z Indexed on 2010/05/12 9:04 UTC
Read the original article Hit count: 90

Filed under:

Hello,

gcc 4.4.3 c89

I have the following source code. And getting a stack dump on the printf.

char **devices;
devices = malloc(10 * sizeof(char*));

strcpy(devices[0], "smxxxx1");

printf("[ %s ]\n", devices[0]); /* Stack dump trying to print */

I am thinking that this should create an char array like this.

devices[0]
devices[1]
devices[2]
devices[4]
etc

And each element I can store my strings.

Many thanks for any suggestions,

© Stack Overflow or respective owner

Related posts about c