How to write to second element of a struct array? In C

struct people
{
    char *name;
    char *surname;
} *human;
human = malloc(10*sizeof(struct people));

Hello everyone. I am trying to acccess elements of this struct array but I think I am doing it wrong. I tried this to access second element's name string human[1].name; And when it didn't worked I tried this human[1.sizeof(struct people)].name; Thanks in advance

Answers


declare the struct and the array that wiill be simpler

typedef struct people
{
    char *name;
    char *surname;
} people;

people  * human=malloc(10*sizeof(struct people));

humam[0].name=malloc((10+1)*sizeof(char));

strcpy(human[0].name,"John");

Don't forget to use malloc for the surname and name because the struct only contains pointers


Need Your Help

Invites on timelines using XFBML

facebook fbml timeline xfbml invite

In my application I am displaying custom invite dialog. This is achived by using FB.XFBML.parse method which parses FBML fb:serverFbml with other content that is responsible for displaying multi-user

Get current running javascript filename after document is loaded

javascript jquery

Is any way to get the file info (file name, path) of a javascript file after the document is ready, without knowing how many scripts or the order how they are loaded?