<div dir="ltr"><div>I have a linked list like this <a href="http://pastebin.com/bwF3jLb6">http://pastebin.com/bwF3jLb6</a> . The problem i am facing is i have initialized the list head and</div><div> then i am doing malloc for that struct object. What i need is i want to make struct abc_st *r as head of linked list and other nodes after it.</div><div><br></div><div>typedef struct abc {</div><div><span class="" style="white-space:pre">        </span>char client_id[18];</div><div>    char mac[18];</div><div>    st_list_head list;</div><div>}abc_st;</div><div><br></div><div>abc_st* check_fields (abc_st *ptr)</div><div>{</div><div>    char cmd[500];</div><div>    MYSQL_RES *result;</div><div>    MYSQL_ROW row;</div><div>    int num_rows;</div><div>    abc_st *r=NULL,*temp=NULL;</div><div>    INIT_LIST_HEAD(&amp;r-&gt;list);   // i have intialized the head here</div><div><br></div><div>    sprintf(cmd, &quot;SELECT * FROM ABCD_TABLE WHERE MAC = %.4x&quot;, ptr-&gt;mac);</div><div>        /* Running the sql query to check for fields with value in database */</div><div>    if (mysql_query(abc_db.db_handle, cmd)) {</div><div>        num_rows = -1;</div><div>        goto done;</div><div>    }</div><div>    result = mysql_store_result(abc_db.db_handle);</div><div>    if (result == NULL) {</div><div>        num_rows = -1;</div><div>        goto done;</div><div>    }</div><div>    num_rows = mysql_num_rows(result);</div><div><br></div><div>    while ((row = mysql_fetch_row(result)))</div><div>    {</div><div>        r= (abc_st *)malloc(sizeof(abc_st));</div><div>        memcpy(r-&gt;mac,row[1],strlen(row[1])+1);</div><div>        memcpy(r-&gt;client_id,row[0],strlen(row[0])+1);</div><div>How should i use list_add ?</div><div>        //list_add(struct list_head *new, struct list_head *head)  //prototype of list_add</div><div>       // list_add(&amp;temp-&gt;list,&amp;r-&gt;list);  //it will go wrong here, i want to make r(structure r as head and then add other strutcure objects)  </div><div>     //   r-&gt;link = NULL;</div><div>        //list_add(r, ptr);</div><div><br></div><div>    }</div><div>done:</div><div>    mysql_free_result(result);</div><div><br></div><div>    return r;</div><div><br></div><div>}</div><div><br></div></div>